Problem sorting with hyperlinks
Problem sorting with hyperlinks
When using a hyperlink, the sort takes into account the "a href" etc., instead of the text that displays. In this example, you can see that Animal Biology -- the only data with a link -- comes first, out of alphabetical order.
https://acm.tru.ca/Page18490.aspx
Also, in the sort option list, it shows part of the URL title, although there is not one specified: Animal Biology">Animal Biology
I'm using version 1.10.2.
I did see this example, but it doesn't appear to work for me:
http://datatables.net/release-datatables/examples/advanced_init/html_sort.html
This question has an accepted answers - jump to answer
Answers
Hi,
This unfortunately is a bug in DataTables :-(. However, thanks for the test case - it was really useful! And with the information from it, I've committed a fix and the nightly is now up-to-date.
Here is your table with the latest fix for DataTables: http://live.datatables.net/qihajala/1/edit .
Regards,
Allan
Thanks!
I just noticed that the second part of the problem is still there. When you click on the list of options at the bottom of the column, there is some garble and it isn't in alphabetical order.
Sorry what list of options? I don't see any?
Allan
At the bottom of each column there is a pop-up you can click on. Each displays a list of the items in the column above, and you can choose one to filter. They are option/select lists. The pop-up under the first column still sorts taking "a href" into account. For example, "Canadian" comes before "Animal."
https://acm.tru.ca/Page18490.aspx
Ah I see it now. You need to strip the HTML from the strings when creating the list - otherwise it is using the raw data as instructed.
So for example, replace:
With:
Allan
OK, now I understand that the HTML has to be stripped, but the code you gave doesn't seem to work. I've also tried a few other regex's for stripping HTML to no avail.
I think it did work, the
select
appears to have been created successfully. What I think the problem is now is the brackets in some of the text. If you select an item that doesn't have brackets, the search works fine.The brackets are being treated as regular expression brackets since that is how the
search()
method is being used.So there are two options:
Don't use regex:
.search( val, true, false )
Continue using regex for a full string search, but expect the characters:
.search( val ? '^'+val.replace('/(/g, '(').replace('/)/g, ')')+'$' : val, true, false )
Allan
Thanks for your help. Much appreciated.