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.className
will work for you. Will eliminate needing to apply it on theth
tag 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.columns
to control which columns SearchBuilder uses. There isn't a SearchBuilder configuration option that can be applied directly usingcolumns
orcolumnDefs
to control which columns are used.The test case shows that you can use
columns.className
to apply the class to one or more columns usingcolumnDefs
instead of applying them to theth
. The test case does work. I don't see theAction
column listed in SearchBuilder. The classunsearchable
is not a SearchBuilder specific class. You can use any classname that makes sense.Kevin
The
searchBuilder.columns
uses any of thecolumn-selector
options. You could use thecolumn-selector
as a function to check the classes of row withorderCellsTop
assigned. The third parameter isnode
which 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
unsearchable
is 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.