Searching on table with some data-search unreliable

Searching on table with some data-search unreliable

dgondgon Posts: 1Questions: 1Answers: 0

Link to test case: [1] https://live.datatables.net/fedepigo/1/edit [2] https://live.datatables.net/yuwaramu/1/edit
Debugger code (debug.datatables.net): N/A
Error messages shown: N/A
Description of problem:
Adding the data-search attribute only in some cells makes the table's search behave, at the very least, unintuitively.

On the first test case, I have added a data-search attribute on the second row, in one of the cells. It doesn't seem to work, as searching "Madrid" doesn't yield any results. Every other search term works, however. I can search names, positions, etc. with no issues. I can even find the cell I added said attribute, just not by that.

On the second test case, the row with the data-search is the first row. It lets me search for Madrid now, but... now it breaks searching for the position of any other rows. Other fields are fine.

Seems like the first row dictates whether data-search will be allowed or not in the rest of the column.
It also seems like having data-search 'allowed' in said column ([2]) will not result in non-attributed cells resorting back on their value.

Admittedly, this does appear in the documentation's comments back since 1.11 ( https://datatables.net/examples/advanced_init/html5-data-attributes.html#Comments ), but it doesn't seem like intended behaviour. If it is so, maybe it should be added to the main documentation.

(Bonus question: Should a cell with a data-search attribute ONLY return results with said attribute, or should it search in BOTH the attribute AND the cell's value?)

Answers

  • allanallan Posts: 63,979Questions: 1Answers: 10,549 Site admin
    edited January 31

    Seems like the first row dictates whether data-search will be allowed or not in the rest of the column.

    That is exactly what is happening.

    DataTables assumes that if you are going to provide a data-search attribute then you are doing to do it for all cells. For performance reasons it will only check for the attribute's existence on the first row in the table. If present it will be used for that column on all rows. If not present, it won't be used at all.

    Should a cell with a data-search attribute ONLY return results with said attribute, or should it search in BOTH the attribute AND the cell's value?

    It will match on the attribute's data only, not the cells content. See this example - search for "AAA" and it will match, but a search for "Tiger" will not.

    Allan

Sign In or Register to comment.