[英]Jquery datatables Plug-In , display “No data available in table” after Sorting/Filtering Data
I use JSON
format for getting data from server to fill DataTables
table. 我使用JSON
格式从服务器获取数据以填充DataTables
表。 In Success part of $().ajax
function , I checked and the response is getting back successfuly. 在$().ajax
函数的Success部分中,我进行了检查,响应已成功返回。 this is the Fiddle for my table : 这是我桌子的小提琴 :
The sample of Json file returning back from server is like this : 从服务器返回的Json文件示例如下所示:
{
"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? 我是在ajax响应后手动创建表,因此以这种方式对数据表有任何问题吗? 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: 2015年12月8日更新的代码:
I updated the code in this fiddle link based on Gyrocode's answer. 我根据Gyrocode的答案更新了该小提琴链接中的代码。
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. 1)当我单击刷新按钮时,该表将再次初始化,但是当我单击排序列或要搜索数据时它将为空。
2)the width of each column is not set correctly. 2)每列的宽度设置不正确。
3)some columns are hidden but they're shown in the table at the end of each row. 3)有些列是隐藏的,但它们显示在每一行末尾的表格中。
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? 4)也要使用正交数据 ,我需要在MM / DD / YY中有日期时间,我在此字段中使用.Net datetime,但是似乎它已更改为Client-side.so的JSON字符串中的TimeStamp。使它成为客户格式?
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: 要考虑的重要事项是:
th
that includes the hidden columns as well. 需要使用正确数量的th
,其中包括隐藏的列。 Use columnDefs
later to hide certain columns. 以后使用columnDefs
隐藏某些列。 tr
/ td
is OK but makes the code complex. 生成tr
/ td
方法可以,但是会使代码变得复杂。 DataTables can send ajax request for you and will handle returned data for you with correct configuration. DataTables可以为您发送ajax请求,并使用正确的配置为您处理返回的数据。 See Orthogonal data example for more information. 有关更多信息,请参见正交数据示例 。 DEMO DEMO
Please see updated jsFiddle for demonstration of corrected code. 请参阅更新的jsFiddle以获得更正代码的演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.