Extra text inserted in th (column header) arial-label attribute
Extra text inserted in th (column header) arial-label attribute
Hi,
I've traced the code and identified this as an issued caused by the regexp used in stripping off html markup for the sTitle.
Example:
var sTitle = col.sTitle.replace( /<.*?>/g, "" );
The regexp above is doing lazy matching, stripping off only html tags but not its content. I have done some tests where the following regexp will strip off the html tags and the content inside:
/<.*>/g
This same regexp - /<.*?>/g
- is used in several places in the source code including the _fnSortAria where the column headers are rendered on sort. I noticed this because we have some html markup (select elements) in the th elements for doing column filtering. Could we have the regexp changed to the proposed one - /<.*>/g
- as above?
Here's a test of the regexp:
https://regex101.com/r/vW1uL7/1
Thanks for looking into this.
Answers
The problem with changing it to greedy matching is that if you had your text in a
span
it would strip out the text in that span as well - and I know a number of people use that technique for additional styling so I can't change it as suggested.That is not to say that a change cannot be made, but I'm not sure what it should be! I'll have a think on it! Feedback is also welcome.
Allan
It is true that a greedy matching would also strip off any column title text in an html tag.
How about making the regexp as an option that can be customized?
I noticed that there are currently 5 places that are using the same regexp. If we go with a option, will it apply in all 5 places or just those involved in column header rendering?
Thanks Allan
The column header is where it is most likely to be of use. I'm not sure about making it an option - this is the first time that I can recalled a request for this. I'm wondering if there is a better solution (ideally without adding too much code to the library!). I'll ponder it...
Allan