How to sort by Date with DataTables jquery plugin?

后端 未结 13 2500
隐瞒了意图╮
隐瞒了意图╮ 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:55

    I realize this is a two year old question, but I still found it useful. I ended up using the sample code provided by Fudgey but with a minor mod. Saved me some time, thanks!

    jQuery.fn.dataTableExt.oSort['us_date-asc']  = function(a,b) { 
      var x = new Date($(a).text()),
      y = new Date($(b).text());
      return ((x < y) ? -1 : ((x > y) ?  1 : 0)); 
    }; 
    
    jQuery.fn.dataTableExt.oSort['us_date-desc'] = function(a,b) { 
      var x = new Date($(a).text()),
      y = new Date($(b).text());
      return ((x < y) ? 1 : ((x > y) ?  -1 : 0)); 
    }; 
    
    0 讨论(0)
提交回复
热议问题