Sorting something akin to an enum

Sorting something akin to an enum

Lone ShepherdLone Shepherd Posts: 11Questions: 0Answers: 0
edited September 2010 in General
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?

Replies

  • Lone ShepherdLone Shepherd Posts: 11Questions: 0Answers: 0
    Anyone?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited September 2010
    There are a number of ways in which this could be done.

    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
  • Lone ShepherdLone Shepherd Posts: 11Questions: 0Answers: 0
    The title sort numeric is exactly what I was looking for -- thanks for pointing me in the right direction!
This discussion has been closed.