SearchBuilder and select column with 2 header rows
SearchBuilder and select column with 2 header rows
Link to test case: https://live.datatables.net/vuronaje/1/edit
Debugger code (debug.datatables.net): NA
Error messages shown: NA
Description of problem: Hello,
I would like to know if there is a way to avoid duplicating the class in the header rows in order to tell the searchBuilder component not to include columns that have a given css class?
I have the orderCellsTop option set to true to tell DataTable that the "real" header is in the first header row.

I works if I have only one header but if I add one header row (for filtering) it does not work anymore.
Is it a small bug or is this the desired behavior?
As discussed here https://datatables.net/forums/discussion/80822/how-to-exclude-columns-for-searchbuilder, wouldn't it be possible to configure the column selection behavior for the "searchBuilder" component via the "columnDefs" option?
This question has an accepted answers - jump to answer
Answers
Maybe using
columns.classNamewill work for you. Will eliminate needing to apply it on thethtag and can be applied throughcolumnDefs. Updated test case:https://live.datatables.net/vuronaje/2/edit
Kevin
Hello @kthorngren,
Are you sure that your test case works?
If you comment the line below (the one I already use to hide the column precisely), it does not work anymore:
"columns": ':not(.unsearchable)'I don't want to specify a column number because it can be anywhere in the data table. I have multiple data tables, each containing different columns.
That's why I want to use a class because it's more generic.
You still need to define
searchBuilder.columnsto control which columns SearchBuilder uses. There isn't a SearchBuilder configuration option that can be applied directly usingcolumnsorcolumnDefsto control which columns are used.The test case shows that you can use
columns.classNameto apply the class to one or more columns usingcolumnDefsinstead of applying them to theth. The test case does work. I don't see theActioncolumn listed in SearchBuilder. The classunsearchableis not a SearchBuilder specific class. You can use any classname that makes sense.Kevin
The
searchBuilder.columnsuses any of thecolumn-selectoroptions. You could use thecolumn-selectoras a function to check the classes of row withorderCellsTopassigned. The third parameter isnodewhich is thecolumn().header()for that particular column. By default this will return the header defined byorderCellsTop.Updated test case:
https://live.datatables.net/vuronaje/5/edit
Note that the class
unsearchableis assigned only to the topth.Kevin
@kthorngren,
Thanks for your answer, it works very nice.
Who knows, maybe a future version of the searchBuilder component will allow us to configure columns using the "columnDefs" option.
It's so much more practical and flexible too
In the meantime, it does the job very well.