Sorting numbers with # in front, and inside an A tag
Sorting numbers with # in front, and inside an A tag
Fringo
Posts: 3Questions: 1Answers: 0
Hi all,
What is the best way to go about having a column with values like #1, #2, #3 etc ?
The content in the td is also inside an A tag. E.g.
<td>
<a class="record-open" data-itemID="1000" href="#">#1</a>
</td>
etc.
I've tried setting column type to 'html-num' to no avail. I've also tried removing the # from the td and using 'render' to apply a function with the # added. Neither option works. The column is still sorted like a string.
Any ideas?
Cheers
This discussion has been closed.
Answers
One option is to use Orthogonal Data to extract the numbers from the
a
tag for thesort
type.Kevin
I see... I think I looked at that but didn't understand it the first time around. I've now used this:
It seems to do the trick. Let me know if you think there's a better way.
Cheers
The above solution aside, it is surprising Datatables doesn't detect this automatically. It is a fairly simple format and I'm guessing its quite commonly used.
You could also try using the Natural sorting plugin.
Maybe this doc will help:
https://datatables.net/manual/data/renderers
Kevin