Array values for data-sort attribute

Array values for data-sort attribute

JordanDJordanD Posts: 2Questions: 1Answers: 0

Hello, I'm relatively new to the DT community and I'm working on my first project with it. I've poked around the forums and the manual a bit but haven't found any examples of this.

Specifically what I'm trying to functionally do is perform two sorts using a single column. For example, when I sort my single column of data, I want it to first sort the data into sections (ex. author or priority), then internally sort each of those sections by another parameter (ex. timestamp or alphabetically).

<!-- Sort by author first, then by timestamp -->
<td data-sort='["Author Name","123456789"]'>

I know the data-sort attribute can be used to change how a table sorts a column, but I'm getting some weird results when I try to pass an array to the attribute.Sometimes it seems to sort lexicographically by array, and sometimes it seems like it's just concatenating the values into a string and sorting on that.

Are array values supported for data-sort, or is it just working by chance when it does? Is there a better way to achieve this same behavior?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,249Questions: 26Answers: 4,761
    Answer ✓

    Sounds like you may want to use columns.orderData. I put together this example for another thread that may help you get started:
    http://live.datatables.net/lurujoru/1/edit

    The results basically are that the first column is sorted by grouping the last name then sorting those on the first name. Other hidden columns contain the first and last names that are used to affect the sort.

    Kevin

  • JordanDJordanD Posts: 2Questions: 1Answers: 0

    Thanks Kevin for your response! I had been experimenting with hidden columns before but hadn't thought to apply the columns.orderData|Option in that way. I was kinda hopping for a solution that was "cleaner" than using hidden columns.

    I found a workaround for my specific situation in the meantime - formatting numbers in a way that makes numerical and alphabetical sort produce the same output. Admittedly it's not really the cleanest solution either, but it's working for now. Thanks anyway. :)

This discussion has been closed.