Order a column that contains a range(a - b) based on the high value (b)
Order a column that contains a range(a - b) based on the high value (b)
crc2220
Posts: 4Questions: 0Answers: 0
Is it possible to tell datatables to rely on the high value(b) when sorting cells that contain (a - b). Can I insert something like <td data-sort="b"> a-b </td> and tell DataTables to rely on that data attribute when sorting that column?
This discussion has been closed.
Replies
Hi @crc2220 ,
Yep, easily done, like this:
See example here,
Cheers,
Colin
Thanks!
Actually I'm still having some issues. Any ideas what's going?
My code is here: http://live.datatables.net/sipakuro/1/edit
Ah, yep, the reason is because it was string sorting (1,10,100,200,3), as opposed to number (1,3,10,100,200) - you can override that by using
columns.type
as in this updated example here.Cheers,
Colin
Worth noting that you can use orthogonal data with HTML attributes as an alternative.
Internally to DataTables its more or less the same as Colin's suggestion, but if you control how the HTML is being created, it can make things a little easier during initialisation since you don't need a function.
Allan
Thank you @colin and @allan !
Both work.