Sorting something akin to an enum
Sorting something akin to an enum
Lone Shepherd
Posts: 11Questions: 0Answers: 0
Let's say I have a table column containing text, that's basically an enum on the back-end.
For example, think about bug-tracking status, you've got new, assigned, in-work, resolved, etc. When you sort on status, maybe you'd want to sort in that order (new, then assigned, then in-work, etc). But a default sort will be alphabetical, ie assigned, in-work, new, resolved, etc.
Is there a way I can embed the sort order/priority inside the td, with a class, and have datatables use that, rather than the actual td field?
For example, think about bug-tracking status, you've got new, assigned, in-work, resolved, etc. When you sort on status, maybe you'd want to sort in that order (new, then assigned, then in-work, etc). But a default sort will be alphabetical, ie assigned, in-work, new, resolved, etc.
Is there a way I can embed the sort order/priority inside the td, with a class, and have datatables use that, rather than the actual td field?
This discussion has been closed.
Replies
One option is to use something like this: http://datatables.net/plug-ins/sorting#Priority - which will detect the words you want and then order them by mapped numbers.
Or you could use something like this: http://datatables.net/plug-ins/sorting#hidden_title - putting the enum value into a hidden element's attribute.
If you want to filter based on the live TD element, you can use DOM sorting: http://datatables.net/examples/plug-ins/dom_sort.html - but it's a bit more expensive since the browser needs to read the DOM for every sort.
Allan