[英]datatables sort by ticks and show date
I'm using Jquery dataTable. 我正在使用Jquery dataTable。 doing ajax call to the server to get json array with data:
执行ajax调用服务器以获取带有数据的json数组:
[{"ticks":635020621354830000,"created":"20/04/13 13:42","action":"1","reference":"1444","fee":"0.6"},{"ticks":635023360450070000,"created":"23/04/13 17:47","action":"0","reference":"1503","fee":"0.6"},{"ticks":635023360461470000,"created":"23/04/13 17:47","action":"0","reference":"1505","fee":"0.6"}]
then I build a table with javascript and call $('#mytable').dataTable({...options}); 然后我用javascript构建一个表并调用$('#mytable')。dataTable({... options}); I want to show first column the "created" data, but to sort it by the "ticks".
我想在第一列显示“已创建”数据,但要按“滴答”对其进行排序。 How can I do it ?
我该怎么做 ? the reason for it so there are many entries in the json array that the "created" field is the same value in "dd/MM/yy hh:mm" format (I don't want to show milliseconds) and the ticks are different.
之所以这样,json数组中有很多条目,“created”字段是“dd / MM / yy hh:mm”格式的相同值(我不想显示毫秒)并且滴答是不同的。
Return the ticks as you do now, but hide them. 像现在一样返回刻度,但隐藏它们。 Use the iDataSort parameter to tell the date column to sort using the hidden column.
使用iDataSort参数指示日期列使用隐藏列进行排序。
See this jsfiddle: http://jsfiddle.net/bFpmJ/ 看到这个jsfiddle: http : //jsfiddle.net/bFpmJ/
In the demo, click on the Column 0 header. 在演示中,单击Column 0标题。 Column 0 values are all the same date, but the table will sort correctly.
第0列的值都是相同的日期,但表格将正确排序。 Column 1 labels which is earliest/latest in agreement with the hidden column.
第1列标签最早/最新与隐藏列一致。
Here is the relevant code: 这是相关代码:
jQuery('#myTable').dataTable(
{
"aoColumns": [
{ "sType":"string", "bSearchable": false, "bVisible": false },
{ "iDataSort": 0 },
null,
null,
null
]
}
);
Note the first column is made invisible and non-searchable. 请注意,第一列是不可见且不可搜索的。 Also, because of the length of the number, the default DataTables sorting wasn't working (perhaps it can't handle a
long
of that length, I'm not sure) - you can see this by just removing the "sType":"string" and then trying to sort by Column 0. So I had to change the "sType" to "string". 另外,由于数字的长度,默认的DataTables排序不起作用(也许它无法处理很
long
的时间,我不确定) - 你可以通过删除“sType”来看到这一点: “string”,然后尝试按列0排序。所以我不得不将“sType”更改为“string”。 Assuming the ticks are always the same number of digits, this shouldn't be a problem. 假设刻度总是相同的位数,这应该不是问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.