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

后端 未结 9 1604
暖寄归人
暖寄归人 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:28

    I believe the existing answers are deprecated due to updates to DataTables. HTML5 supports attributes that DataTables can use to easily sort columns. Specifically the data-sort attribute. (See https://datatables.net/examples/advanced_init/html5-data-attributes.html)

    I can easily sort tables like so:

    Name Age
    John Doe 2/1/78 (37 years old)
    Jane Doe 12/1/80 (35 years old)

    It doesn't matter that the 'Age' column contains numbers, symbols, and letters, DataTables will sort using the 'data-sort' attribute.

提交回复
热议问题