SearchBuilder and select column with 2 header rows

SearchBuilder and select column with 2 header rows

sloloslolo Posts: 70Questions: 14Answers: 1

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

  • kthorngrenkthorngren Posts: 21,896Questions: 26Answers: 5,059
    edited April 11

    Maybe using columns.className will work for you. Will eliminate needing to apply it on the th tag and can be applied through columnDefs. Updated test case:
    https://live.datatables.net/vuronaje/2/edit

    Kevin

  • sloloslolo Posts: 70Questions: 14Answers: 1

    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.

  • kthorngrenkthorngren Posts: 21,896Questions: 26Answers: 5,059
    edited April 11

    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 using columns or columnDefs 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 using columnDefs instead of applying them to the th. The test case does work. I don't see the Action column listed in SearchBuilder. The class unsearchable is not a SearchBuilder specific class. You can use any classname that makes sense.

    Kevin

  • kthorngrenkthorngren Posts: 21,896Questions: 26Answers: 5,059
    Answer ✓

    The searchBuilder.columns uses any of the column-selector options. You could use the column-selector as a function to check the classes of row with orderCellsTop assigned. The third parameter is node which is the column().header() for that particular column. By default this will return the header defined by orderCellsTop.

    Updated test case:
    https://live.datatables.net/vuronaje/5/edit

    Note that the class unsearchable is assigned only to the top th.

    Kevin

  • sloloslolo Posts: 70Questions: 14Answers: 1

    @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.

Sign In or Register to comment.