Exclude rows from search

Exclude rows from search

DataTableFanDataTableFan Posts: 7Questions: 3Answers: 0

Rows with a specific class (or row indexes) should be ignored by the search and remain visible although the search term does not fit. My use case is that new rows are added dynamically and therefore some columns are not filled yet and so they are currently hidden because of an existing search.

I tried it with $.fn.dataTable.ext.search.push(...) but this is just an additional search filter.

Is there an option for this requirement or can I override the default behavior in some way?


  • kthorngrenkthorngren Posts: 4,828Questions: 19Answers: 1,063

    There is no builtin option for this. Maybe a regex search could work:
    table.search( '(' + searchVal + '|' + ignored + ')', true, false ).draw();

    Example here:

    This should return any rows that have the searchVal or the value to ignore. You could then use orthogonal data and set the search type to the value you want to ignore using columns.render.

    My first thought was the search plugin approach but I think you are right it would pass along the rows with the ignored value only to be filtered later.


  • DataTableFanDataTableFan Posts: 7Questions: 3Answers: 0

    Nice idea but a seach type is not triggered after initialisation while using your keyup function or global search function (e.g. sort type is triggered). live.datatables.net/zuqusovu/6/edit?js,console,output

    It would be also fine to show the hidden rows after the search.dt event was triggered if all data (e.g. filtered info) is updated correctly. Something like a positive search (add all kind of matches) and not a negative filter (remove all not matching ones).

    One main problem is, that the search just analyse the cell data and not e.g the td classes or attributes (or in my case the rows data).

  • kthorngrenkthorngren Posts: 4,828Questions: 19Answers: 1,063

    Nice idea but a seach type is not triggered after initialisation

    Sorry its filter not search. I believe the render for the filter type only runs at initialization. However if you make changes to the Datatables data then I expect it will run again when a table draw occurs. At least thats my understanding. When searching Datatables will use that type for searching but the render function won't run against it.

    I modified your example a bit to show what I mean.

    If anything in the age column is above 50 the filter data is returned as above 50. All these rows should be included in the search. The example could be made better by having a hidden column that you have the above 50. Otherwise searching for a number greater than 50 in the default search will not work.

    I'm not familiar with any options to search by using the td elements. Datatables will search using the HTML5 data elements. I haven't messed with it much but maybe you can set a data attribute to match your class or attribute you are interested in. This is covered in the orthogonal doc page.


Sign In or Register to comment.