Search only on one column

Search only on one column

spiderkznspiderkzn Posts: 44Questions: 12Answers: 0

Hi,

I have Datatable which display whole data no problem. However the search input that when I type it filter everything in table. but I would like to filter on one specific column.

I've tried add searchable: false, and it not working.

Please help

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421
    edited February 8 Answer ✓

    If you want to use the global search field for that you can set the other columns to "not searchable"

    If you use a class for those columns you could do:

    columnDefs: [
       // targets may be classes
        {   targets: "noSearchCols", searchable: false      },
    ],
    

    Alternatively you can hard code the columns positions and do it like this:

    columnDefs: [
        {targets: [0, 1, 2, 3, 4, 5], searchable: false}
    ],
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Use columns.searchable to disable search on specific columns. In this case disable it on all but the one you want to be searchable.

    Allan

  • spiderkznspiderkzn Posts: 44Questions: 12Answers: 0

    Thank you rf1234, the code below has solved the problem.

    {targets: [0, 1, 2, 3, 4, 5], searchable: false}

Sign In or Register to comment.