jQuery datatable datetime-moment插件未正确排序 [英] Jquery datatable datetime-moment plugin not sorting properly

查看:107
本文介绍了jQuery datatable datetime-moment插件未正确排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下大型html表: https://gist.github.com/hbizira/21016ff3df67fdae3969

I have the following large html table: https://gist.github.com/hbizira/21016ff3df67fdae3969

我正在使用datetime-moment datatables插件.在以上文件的末尾,我具有以下javascript代码:

And I'm using the datetime-moment datatables plugin. At the end of the above file, I have the following javascript code:

$(document).ready(function() {
    $.fn.dataTable.moment( 'MM/DD/YYYY hh:mm A');
    window.dataTable = $('#leads').dataTable({
        displayLength: 25,
        lengthChange: false,
        statesave: false
    }).columnFilter([
            { column_number: 1, filter_type: "range_date", filter_container_id: "leads_filter_date_range", filter_default_label: [ "From", "To" ] },
            { column_number: 11,
              filter_type: 'custom_func',
              custom_func: customStatusFilter,
              data: [
                  { value: 'pending', label: 'Pending' }, 
                  { value: 'qualified', label: 'Qualified' }, 
                  { value: 'pending_and_qualified', label: 'Both Pending & Qualified' }
              ],
              filter_container_id: "leads_filter_status",
              filter_default_label: ""
            },
        ]
    );

});

但是,最后采取的行动"列似乎根本无法正确排序.当我尝试按该列中的最新条目排序时,2015年的条目不会显示.

However, the "last action taken" column doesn't seem to sort properly at all. There are entries from 2015 that don't show up when I attempt to sort by most recent entry in that column.

http://recordit.co/1V8gzsqrso

推荐答案

由于日期字符串moment.js返回为Date.parse() able',因此您可以这样做:

Since the date strings moment.js returns is Date.parse()able' you can do this :

columnDefs : [
    { type : 'date', targets : [13] }
],  

,现在该列已正确排序.

and now the column is sorted correctly.

具有来自github的(大部分)表的演示-> http://jsfiddle.net/t6snpgkf/

demo with (most) of your table from github -> http://jsfiddle.net/t6snpgkf/

我相信,但在这种情况下尚未进行测试,因为它包含空值,所以dataTables确定该列的类型为string-因此,您必须强制使用date类型.

I believe, but have not tested it in this case, that dataTables determines that the column is of type string since it contain empty values - thus you must force the date type.

这篇关于jQuery datatable datetime-moment插件未正确排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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