Sort by non-cell data; how to access data?
Sort by non-cell data; how to access data?
I have a non-ajax table that I wish to make sortable using DataTables. One column contains a lot of HTML that is irrelevant for the purposes of sorting. I want to sort by a number somewhere in the HTML. The HTML confuses the sorting algorithm, causing the sorting to appear wrong to humans. For example:
[code]
...
...
...
NUMBER
...
[/code]
My first thought was I could add an HTML5 data attribute () then access this value inside the aTypes/oSort functions. This did not work as these functions have no reference to the actual cell being examined.
What is the best way to handle this?
I looked into using mData. Best I can tell, that appears to be mostly for ajax, where I already have a rendered table. Also the mData function does not receive a reference to the table cell so the HTML5 data attribute would still not be available.
Thanks.
[code]
...
...
...
NUMBER
...
[/code]
My first thought was I could add an HTML5 data attribute () then access this value inside the aTypes/oSort functions. This did not work as these functions have no reference to the actual cell being examined.
What is the best way to handle this?
I looked into using mData. Best I can tell, that appears to be mostly for ajax, where I already have a rendered table. Also the mData function does not receive a reference to the table cell so the HTML5 data attribute would still not be available.
Thanks.
This discussion has been closed.
Replies
I can't imagine what that might entail - could it not be handled by CSS styling?
* The total score (NUMBER)
* Image/text describing whether or not all scores are "complete"
* A div with a title attribute displaying all historical scores that produce the total score
The extra content is considered in the default sorting algorithm, but when the user clicks the th to sort, the user expects the column to be sorted by the total score only. This is why I want to sort by NUMBER, and not the actual td contents.
Yes! Although that won't work with DataTables 1.9-, it will with 1.10+ :-).
There is an example here: https://github.com/DataTables/DataTables/blob/master/examples/advanced_init/html5-data-attributes.html . I don't have a running example of it hosted yet as 1.10 isn't quite in beta yet, but you can try it out from the nightly: http://datatables.net/download .
The other option is to write a sorting plug-in which will strip the data to just the number, but the HTML5 route is much more preferable in my book.
Allan
Thanks.