ordering changes after using render on column?
ordering changes after using render on column?
mihomes
Posts: 165Questions: 23Answers: 0
The 8th column in my dt is a timestamp column and I am using this as the default order as so :
[code]"order": [[8,'desc']][/code]
An example of the output in this column correctly shows in descending order.
2014-04-01 20:05:00
2014-04-01 16:27:00
2014-04-01 12:27:00
2014-04-01 09:28:00
2014-03-31 20:13:00
2014-03-31 18:41:00
2014-03-31 14:13:00
Now, if I render this column to show a more user friendly output with :
[code]
{
"render": function ( data, type, row ) {
if (data == '')
{
return 'n/a';
}
else return $.format.date(data, 'MMMM D, yyyy @ h:mm a');
}
}
[/code]
the output in my table becomes :
March 31st, 2014 @ 8:13 PM
March 31st, 2014 @ 6:41 PM
March 31st, 2014 @ 2:13 PM
April 1st, 2014 @ 9:28 AM
April 1st, 2014 @ 8:05 PM
April 1st, 2014 @ 4:27 PM
April 1st, 2014 @ 12:27 PM
which is no longer in the same order. Shouldn't ordering stay the same (using the default data shown above) regardless of what rendering I apply to it? Is there any way I can correctly order these rendered dates?
This particular table is using dom elements (whereas all my others user server-side)... is that the reason why ordering is behaving in this manner? The reason I am using dom is because I could not sort non-database values I was inserting into the table.
[code]"order": [[8,'desc']][/code]
An example of the output in this column correctly shows in descending order.
2014-04-01 20:05:00
2014-04-01 16:27:00
2014-04-01 12:27:00
2014-04-01 09:28:00
2014-03-31 20:13:00
2014-03-31 18:41:00
2014-03-31 14:13:00
Now, if I render this column to show a more user friendly output with :
[code]
{
"render": function ( data, type, row ) {
if (data == '')
{
return 'n/a';
}
else return $.format.date(data, 'MMMM D, yyyy @ h:mm a');
}
}
[/code]
the output in my table becomes :
March 31st, 2014 @ 8:13 PM
March 31st, 2014 @ 6:41 PM
March 31st, 2014 @ 2:13 PM
April 1st, 2014 @ 9:28 AM
April 1st, 2014 @ 8:05 PM
April 1st, 2014 @ 4:27 PM
April 1st, 2014 @ 12:27 PM
which is no longer in the same order. Shouldn't ordering stay the same (using the default data shown above) regardless of what rendering I apply to it? Is there any way I can correctly order these rendered dates?
This particular table is using dom elements (whereas all my others user server-side)... is that the reason why ordering is behaving in this manner? The reason I am using dom is because I could not sort non-database values I was inserting into the table.
This discussion has been closed.
Replies
No, because your rendering function is returning a date format that the `Date.parse()` function in Javascript doesn't understand, and that data is being used for the order.
However, you can use the `render` function to return different data for type detection and sorting - see http://next.datatables.net/manual/orthogonal-data#Computed-values
Allan
I don't suppose there is a way to do this with server-side is there? I have a situation where I have one value (an ip address) in the database. I use this ip address in another function to return its city, state, country, etc. which are not in the database. I can do this, but of course the sorting and searching does not work as it sees the ip and not the newly rendered value.
Hope that makes sense.