HTML sort type bug?

HTML sort type bug?

jsmreesejsmreese Posts: 6Questions: 0Answers: 0
edited June 2010 in Bug reports
One column of my table has mouseover javascript:
[code]
~Name~
[/code]
This column is initialized with sType as html, and is filtered by an input text box that filters on that column only:
[code]
$("thead td.nSearch input").keyup( function () {
oTable.fnFilter( this.value, $("thead td.nSearch input").index(this) );
} );
[/code]
What *should* be matched on filter is only the ~Name~ which gets replaced with actual names when the table is generated.

What *is* matched is everything after and including this: , WIDTH
Up until and including the final result of ~Name~
The trailing doesn't seem to be matched, and I don't believe the preceding ' is matched.

Replies

  • jsmreesejsmreese Posts: 6Questions: 0Answers: 0
    edited June 2010
    And now having posted that it occurs to me that sType might only govern how the data is sorted, not how it is filtered... the sorting itself does work properly, and I may be on the wrong tangent all together!

    And BTW, I see this in both IE 8.0 and Firefox 3.5.9.
  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin
    sType will effect both sorting and filtering when it is set to a type of 'html'. It should strip both the html for both sorting and filtering and then act as needed. Unfortunately the method for stripping the html tags is not very intelligent, and simply does: .replace(/\n/g," ").replace( /<.*?>/g, "" ); ... Therefore inner tags can cause the parser to get upset.

    I'll have a look at how difficult it will be to correct this...

    Allan
  • jsmreesejsmreese Posts: 6Questions: 0Answers: 0
    edited June 2010
    Thanks for your quick response. My solution was fairly simple, I patched the 'html' section of the function _fnDataToSearch to this instead:
    [code]
    .replace(/\n/g," ").replace( /<[^\r\n<>]*?>/g, "" ).replace( /<[^\r\n<>]*?>/g, "" );
    [/code]
    This only removes nested HTML tags that are nested two deep (as mine are with the HTML within the mouseover function) so it's not a completely general solution but it is a little smarter than the previous version and isn't much slower.

    John
  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin
    Hi John,

    I've just been investigating how this can be improved in DataTables, and found a suitable solution. It does have a slight performance impact though, so what I've done is to wrap it up into a plug-in filtering function: http://datatables.net/plug-ins/filtering#html_column .

    This will replace the built-in 'html' filtering method for an 'html' type column with a method for complete removal of tags. I've not included it in DataTables by default due to the performance impact, and this is a fairly rare use case - but it is there if you (or anyone else!) would like to use it now :-) Note that it might be suitable to do this for a sort function as well...

    Regards,
    Allan
This discussion has been closed.