How to use columnSelector for columns selecting

How to use columnSelector for columns selecting

VyacheslavVyacheslav Posts: 70Questions: 27Answers: 0

I don't understand how to use columnSelector if I need to select only searchable columns i.e
columnDefs: [
{ searchable: true, targets: 1 },
{ searchable: false, targets: 2 }
]

What should I do with parameter for the method: columns( ??? ) ?
And If I want to add a custom column-attribute, how to use it with columns() ?

This question has an accepted answers - jump to answer

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43
    Answer ✓

    I don't think you can select searchable columns directly. You can use a class to apply searchable vs no searchable,columnDefs.targets, and then use that class as a selector in other places. I usually put these classes in the column header of the table.

    What sort of custom attribute would you apply? There are several ways to apply attributes. You can use the createdRow call back to process specific cells. You can use the columns().every() to loop through columns. In either case, once you have the correct cell, you can use jQuery to add any attributes.

  • VyacheslavVyacheslav Posts: 70Questions: 27Answers: 0

    Thank you ThomD

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    I found a way to do it using a function as a selector, but its kinda hairy. you need to poke around through the aoColumns object in the DT Settings, you check if aoColumns.i.bSearchable is true, (where i = column index)

    So honestly, id suggest going with @ThomD method anyways

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    I don't think you can select searchable columns directly

    Currently no - I intend to add an API for that in future which will allow this (likewise orderable columns) and its just not something I've ever gotten around to. At the moment the class name option is the best way.

    Allan

This discussion has been closed.