I have a column that was pure text and the sorting worked fine but when I change the column data to HTML regular links, the sorting seems quite random and broken. I couldn\
Use sSortDataType and sType (with value html
) to notate the column as containing HTML and remove it prior to sorting. Docs on the Columns page.
The way I resolved the column sort with links is to use server side processing. This sets the sort process on the server side code, where the sort is handled by SQL. The link is added to each row after the fact. The resultant returned to the client side displayed correctly. Otherwise, the answer by tvanfosson seems to work well.
It sounds like the table is being sorted on the literal HTML strings, rather than the text. I haven't used that plugin but there is probably a way to override the default sorting method.
If not, give TableSorter a try, because it does this.
I would check the source of the plugin, and see if it's sorting on something like this
var sortText = $(this).html();
and change the html()
method to text()
. This will strip out all tags and sort it on the text node only.