Sorting with preprocessing?
Sorting with preprocessing?
I have a list of dates -- like February 5, 2024 23:04:52 in a datatable-powered table -- that I'd like to sort. I think I'll need to do the following:
- Convert the column to epoch timestamps.
- Sort the epoch values.
- Convert back to the format in the question.
I guess what I'm trying to find is a way to convert the relevant column to epoch time or sort on an attribute value in the relevant HTML tag. Calculating the epoch equivalent is done using moment.($('tr > td[3]').text().replace(' ', 'T')).valueOf(). I can store this value as an attribute, but how do I tell sort() to use that as the comparator? Thanks for the help, in advance.
Answers
You can use orthogonal data data to do that. In this example, a string is being converted into a number which is then used for sorting. You can use
columns.render
to do something similar, such as forsort
return that epoch timestamp calculated by Moment.js.Colin
Another option is to use the sorting plugin described in this blog.
Kevin