How to sort by Date with DataTables jquery plugin?

后端 未结 13 2635
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 11:02

I am using the datatables jquery plugin and want to sorty by dates.

I know they got a plugin but I can\'t find where to actually download it from

http://data

13条回答
  •  庸人自扰
    2020-12-02 11:40

    I Have 10 Columns in my table and there is 2 columns of dates, 2nd column and 4th column is of US Date, so this is worked for me fine. Just paste this code at last in your script section in same sequence.

       jQuery.fn.dataTableExt.oSort['us_date-asc'] = function (a, b) {
            var x = new Date(a),
                y = new Date(b);
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
        };
    
    
        jQuery.fn.dataTableExt.oSort['us_date-desc'] = function (a, b) {
            var x = new Date(a),
                y = new Date(b);
            return ((x < y) ? 1 : ((x > y) ? -1 : 0));
        };
    
    
        $('#tblPoSetupGrid').dataTable({
            columnDefs: [
                { type: 'us_date', targets: 3 },
                { type: 'us_date', targets: 1 }
            ]
    
        });
    

提交回复
热议问题