Sorting and column types
Sorting and column types

Summary: I have a string-format column that has a defined sort field that is an integer. When I sort that column, it sorts by string, not int.
columns: [
{data: 'client'},
{data: { '_': 'support_time',
'sort': 'support_time_sort' }
},
...
support_time
is an hh:mm:ss string (eg, 2:27:53) and support_time_sort
is an integer (actually the number of seconds of time, so in this example 8873). For testing, I'm showing both the support_time
and support_time_sort
columns. When I sort on the support_time
column, it sorts by support_time_sort
as a string (ie, 527 before 61); the support_time_sort
column correctly sorts as an integer.
I think I need to specify that the support_time
column is of num format, but I'm struggling to get the syntax right.
- Is that the right way of fixing this?
- Could someone give an example of how I specify
{type: num}
for that column?
This question has an accepted answers - jump to answer
Answers
The developers can confirm but it seems that when rendering the
filter
value Datatables always treats it as a string not a number. I even tried forcing it with usingcolumns.render
and using various techniques likeNumber()
to return a numeric filter value.The answer I found is to use
orderData
. You will need to create asupport_time_sort
column but can usecolumns.visible
to hide it.Here is an example using your config,
columns.render
andorderData
:http://live.datatables.net/rajacoge/1/edit
If you don't want to use
orderData
then another option might be to usecolumns.render
and return zero padded strings, ie,0527
,0061
, etc.Kevin
That worked perfectly. Thank you so much for your help - I'd spent ages trying to fix that!