afnFiltering - is there any way to filter on attributes of elements rather than their contents?

afnFiltering - is there any way to filter on attributes of elements rather than their contents?

cesincocesinco Posts: 5Questions: 0Answers: 0
edited June 2013 in DataTables 1.9
I posted earlier about a problem I was having with afnFiltering not even firing and while I have not been able to solve this when running on server-based code, I was able to get further when running local HTML files. Regardless, I have now run into an issue where my attempts to use afnFiltering only half work. The reason is because rather than trying to filter on the text contained within a cell of the table, I am trying to filter on an attribute (specifically class, which may contain multiple class names). This works while the whole table is displayed but fails after the table has been filtered once. The reason is that iDataIndex parameter cannot be used to iterate through the rows of the table when the table has had some rows removed through filtering because an out-of bounds error will occur (table rows are actually eliminated rather than hidden?) so an iDataIndex that was valid when the table of 10 rows (for example) was first built, will not be valid any longer for row 8,9,10, when the table has been filtered down to 7 rows.

Using the aData parameter doesn't help because that only stores the text of the cells and not attributes on which my filtering works, even though it may still hold all 10 row values.

Any suggestion son how to solve this?

Replies

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Currently DataTables is a bit limited in this way, although I am looking at trying to fix that in 1.10.

    What you currently need to do is something like:

    [code]
    function( oSettings, aData, iDataIndex ) {
    var tr = oSettings.aoData[ iDataIndex ].nTr;
    ...
    }
    [/code]

    From there you have the TR element and you can query it for its child elements. Not obvious and not vey performant, but I am looking at making it easier! :-)

    Allan
  • cesincocesinco Posts: 5Questions: 0Answers: 0
    OK - thanks for the reply. In the end, I managed to use the cell contents and not its attributes so this point is a bit moot. My initial reason for using attributes rather than cell contents is because cells containing all sorts of characters such as\, &, etc. don't work very well with regular expression filtering (I have determined that my original question was due to this). So, my workaround was to keep the cell contents and generate a key, stored in the class attribute on which my filtering could occur. I'll keep an eye out for your updates just the same because the next time, I may not have a choice but to use RegExp filtering with cell contents containing reserved RegExp characters.
This discussion has been closed.