Column natural sort does not work if cells have hyper links
Column natural sort does not work if cells have hyper links
derekwallace
Posts: 11Questions: 0Answers: 0
Hi,
I have cells that have hyperlinks.
<td><a href='Could be anything'>SortThisString</a></td>
Im using the natural sort plugin.
var table = $('#example').DataTable(
{
"columnDefs" : [{ type: 'natural', targets: '_all' }]
}
However the sorting is not correct.
What i believe is happening is that the html element code is being used as part of the sort.
Since the href value is before the display value, it is the thing that takes priority
in the sort.
Example of problem here.
http://live.datatables.net/zuxevobe/4/edit
Thx
derek
This discussion has been closed.
Replies
I played around with the natural.js that is used for column sorting.
I found this on SO.
http://stackoverflow.com/questions/5002111/javascript-how-to-strip-html-tags-from-string
So i added some code to the natural.js to pre-process the a and b inputs to remove the html tags and just leave the text.
Seems (so far) to work well.
Let's merge this conversation with this one: https://www.datatables.net/forums/discussion/27125 .
Allan