如何在PHP中的datatable插件中排序datetime字段? [英] How to sort the datetime field in datatable plugin in PHP?

查看:344
本文介绍了如何在PHP中的datatable插件中排序datetime字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于在datatable plugin中排序日期和时间字段,但它不能按照9,8,7,... 12,11,10的顺序排序。如果我使用一些自定义代码排序我的作品,但它不是排序某些数据的

I'm used to sort the date and time field in datatable plugin.but it not working it sort in the order of 9,8,7,...12,11,10. If I'm use some custom code for sorting I works but it is not sorting for some data's

自定义代码:

HTML和JS

<td><?=  $date ? $date : '-' ?></td>

jQuery.fn.dataTableExt.oSort['uk_date-pre'] = function(a) {
var a = a.split('m')[0];
a=a+'m';
a = a.slice(0, -2) + ' ' + a.slice(-2);
var date = Date.parse(a);
return typeof date === 'number' ? date : -1;
}

datatable:

datatable:

$('#id').DataTable({
    "paging": true,
    "ordering": true,
    "aoColumns": [
       { "bSortable": false },  
       { sType: 'uk_date' },
       null
    ],
    "order": [[0, 'desc']],
});


推荐答案

最后我得到了答案,评论

Finally i got the answer thanks you for all for your comments

jQuery.fn.dataTableExt.oSort['uk_date-pre'] = function(a) {
var a = a.split('m')[0];
if(a == '-'){
        return -1;
    }
a=a+'m';
a = a.slice(0, -2) + ' ' + a.slice(-2);
var date = Date.parse(a);
return typeof date === 'number' ? date : -1;
}

这篇关于如何在PHP中的datatable插件中排序datetime字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆