How can I get jQuery DataTables to sort on hidden value, but search on displayed value?

后端 未结 9 1627
暖寄归人
暖寄归人 2020-12-08 09:47

I have a simple DataTables grid which contains date columns. I have provided two values for the date in my JSON data set, one for display and one specifically designed so th

9条回答
  •  渐次进展
    2020-12-08 10:37

    +1 JocaPC

    I'd like to add to JocaPC's answer by reminding everyone that javascript utilizes zero-indexed arrays.

    Example:

    HiddenSortString (0) | Date (1)                   | Some Text (2)
    ...................................................................
    1349035566           | September 30, 2012 2:06 pm | blah blah
    1349118137           | October 01, 2012 1:02 pm   | blah blah
    1349371297           | October 04, 2012 11:21 am  | blah blah
    ...................................................................
    

    To sort the date field using the hidden string you would use the following.

    $('.mytable').dataTable({
        "aoColumns": [{"bVisible": false},{"iDataSort": 0},null]
    });
    

提交回复
热议问题