Jquery数据表插件,显示“表中无数据”排序/过滤数据后 [英] Jquery datatables Plug-In , display "No data available in table" after Sorting/Filtering Data
问题描述
我使用 JSON
格式从服务器获取数据以填充 DataTables
表。
在 $()。ajax
函数的成功部分,我检查并且响应成功地恢复。
这是我的表格中的小提琴:
从服务器返回的Json文件示例如下所示:
{
data :[
{
__type:TEST1.Campaign,
BookingID:0,
CatalogueNumber:IEM201343000007,
CampaignId :34,
StartTime:/ Date(1438437600000)/,
EndTime:/ Date(1440079200000)/,
DurationPlayout:3,
AdDuration:5,
CampaignType:facebook,
站:[
7mate.brisbane.au,
eleven.brisbane.au
nine.brisbane.au
],
Client_ID:192,
ContactID:5851,
AdvertiserID:9228,
活动:true,
SModified:null,
DSP:SiteScout,
ClientName:,
AdvertiserName:HA Consulting,
ContactName:Aisling Bannan
}
]}
我在ajax响应后手动创建表,所以有以这种方式发生数据的任何问题?
当我过滤或按列排序表记录时,会出现此问题:
表中没有数据
任何帮助将不胜感激。 p>
12/08/2015 更新代码
我更新了这个小提琴链接基于 Gyrocode的答案。
1)当我点击刷新按钮时,表正在初始化,但是当我点击排序列或想要搜索数据时,表将为空。
2)每列的宽度设置不正确。
3)某些列被隐藏,但它们显示在每行末尾的表中。
4)还用于使用正交数据,我需要在MM / DD / YY中有datetime,我使用.Net datetime为该字段,但似乎更改为时间戳在Client-side.so中的JSON字符串,是否有任何方式使其成为托管格式?
原因
您的代码有许多语法错误和其他问题,这个答案也是很长时间列出他们所有。
要考虑的重要事项是:
- 需要使用正确的数量
th
也包括隐藏的列。稍后,请使用columnDefs
隐藏某些列。 - 生成
tr
/td
正常,但使代码复杂。 DataTables可以为您发送ajax请求,并将以正确的配置为您处理返回的数据。有关详细信息,请参阅正交数据示例。
DEMO
请参阅更新的jsFiddle ,以显示更正的代码。
I use JSON
format for getting data from server to fill DataTables
table.
In Success part of $().ajax
function , I checked and the response is getting back successfuly.
this is the Fiddle for my table :
The sample of Json file returning back from server is like this :
{
"data": [
{
"__type": "TEST1.Campaign",
"BookingID": 0,
"CatalogueNumber": "IEM201343000007",
"CampaignId": 34,
"StartTime": "/Date(1438437600000)/",
"EndTime": "/Date(1440079200000)/",
"DurationPlayout": 3,
"AdDuration": 5,
"CampaignType": "facebook",
"Stations": [
"7mate.brisbane.au",
"eleven.brisbane.au",
"nine.brisbane.au"
],
"Client_ID": 192,
"ContactID": 5851,
"AdvertiserID": 9228,
"Active": true,
"SModified": null,
"DSP": "SiteScout",
"ClientName": "",
"AdvertiserName": "H A Consulting",
"ContactName": "Aisling Bannan"
}
] }
I'm creating the table manually after ajax response, so Is there any issue with datatables in this way? when I filter or Sort the table records by a column , this issue happens:
No data available in table
Any Help would be appreciated.
12/08/2015 Updated Code:
I updated the code in this fiddle link based on Gyrocode's answer.
1)when I click refresh button, the table is initializing again,but it will be empty when I click sort columns or want to search data.
2)the width of each column is not set correctly.
3)some columns are hidden but they're shown in the table at the end of each row.
4)Also for using Orthogonal data, I need to have datetime in MM/DD/YY, I used .Net datetime for this field , but it seems it changed to TimeStamp in JSON string at Client-side.so, is there any way to make it in custome format?
CAUSE
There are many syntax errors and other issues with your code, this answer would be too long to list them all.
Important things to consider are:
- Need to use the correct number of
th
that includes the hidden columns as well. UsecolumnDefs
later to hide certain columns. - Your approach with generating
tr
/td
is OK but makes the code complex. DataTables can send ajax request for you and will handle returned data for you with correct configuration. See Orthogonal data example for more information.
DEMO
Please see updated jsFiddle for demonstration of corrected code.
这篇关于Jquery数据表插件,显示“表中无数据”排序/过滤数据后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!