Applying columns().search() for two columns doesn't work
Applying columns().search() for two columns doesn't work
According with documentation columns().search() give the possibility to add custom column search based on CSS class name.
See https://jsfiddle.net/ck08w37h/5/
In HTML I have:
Input box tu enter word
<input type="text" id="keyword" name="mots-cles" >
Two colomns with class="status"
<thead>
<tr>
<th class="status">Name</th>
<th class="status">Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
In JavaScript I have a handler for imput box:
$("#keyword").on( 'keyup click', function () {
var recherche = $(this).val();
//table.search(recherche).draw();
table.columns('.status').search(recherche).draw();
});
When I type "Airi" in input box I expect to have two raws selected. But I don't have nothing
This question has an accepted answers - jump to answer
Answers
I putted the "Airi" data in each column "Name, Position, Office".
I expect only the data in "Name, Position" will be shown because the CSS class is present on this columns
So the issue here is that
columns().search()
applies to search to every column individually. It does not match on just a single column, but all of them. So you would need to have "Airi" in all columns that you are searching on!That is unfortunately a limitation in DataTables at the moment which I hope to address in future. The global search operates the way you want (
search()
) but not the column search I'm afraid. For that you would need a custom search plug-in.Allan
Do you have example for a custom search plugin that has a behavior like global search but for two columns. Thanks for your effort.
Sorry no - that's not code that I've written before.
Allan
if i recall right, columns have an attribute called searchable - or is this only for the request on serverside processing?
There is
columns.searchable
, but that only effects the columns ability to be searched. It doesn't effect how the search spans the columns, which is the issue here.Allan