Can searching and columnDefs be used together

Can searching and columnDefs be used together

dotpydotpy Posts: 1Questions: 1Answers: 0

Can/Should https://datatables.net/reference/option/searching and columnDefs be used together, e.g?

"searching": false,
"columnDefs": [{
    "searchable": true, "targets": 1,2,4,6
}],

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    "searching": false,

    Setting searching to false does two things; first it disables Datatables searching and second it eliminates the display of the global search input.

    "searchable": true, "targets": 1,2,4,6

    First it should be an array of targets, for example "targets": [1,2,4,6]. For this to work you need to have searching set true which is the default. The default value of columns.searchable is true. You will need to turn off the columns you don't want to search.

    If you want to remove the global search input but search only certain columns then use the layout option to remove the search input by setting topEnd: null false. Next you will need to apply columns.searchable false to the columns you don't want to search. You can use an array of column indexes or set a class name on the th, ie no_search, for the columns you don't want to search. Use the class name in the columnDefs.targets. For example:
    https://live.datatables.net/nivivade/1/edit

    Kevin

Sign In or Register to comment.