data search in a column using OR for terms that have multiple words
data search in a column using OR for terms that have multiple words
z3phir
Posts: 3Questions: 1Answers: 0
hi
i want to search in a column using OR for terms that have multiple words
any idea how i would achieve that ?
one of the fields relevant to my problem would be like this (how i would like to define it)
<select class="column_filter" data-column="3" id="col3_filter">
<option value="">All</option>
<option value="search for me OR for me OR for me OR multiple words">Group 1</option>
<option value="some other value">some other value</option>
</select>
the js part
function filterGlobal() {
$('#searchResults').DataTable().search(
$('#global_filter').val(),
false,
true
).draw();
}
function filterColumn(i) {
$('#searchResults').DataTable().column(i).search(
$('#col' + i + '_filter').val(),
false,
true
).draw();
}
$('.global_filter').on('keyup click', function () {
filterGlobal();
});
$('.column_filter').on('keyup click change', function () {
filterColumn($(this).attr('data-column'));
});
$('#searchResults').DataTable({
responsive: true,
columns: [
{responsivePriority: 0},
{responsivePriority: 1},
{responsivePriority: 2},
{responsivePriority: 3},
{responsivePriority: 4}
],
"order": [[4, "desc"]]
});
html
<tr>
...
<td data-search="search for me">something</td>
...
</tr>
<tr>
...
<td data-search="for me">something</td>
...
</tr>
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Please build a simple example of your table and the select list that you want use. This way we can see exactly what you have and provide more specific help. You can start with this template:
http://live.datatables.net/
Kevin
thanks for responding kevin
sorry for the late replay but i did not get a notification about your response
here is the example i hope is easy to understand i simplified as much as possible
http://live.datatables.net/ginayero/1/edit
Thanks that helps. I updated your example which seems to work:
http://live.datatables.net/ginayero/2/edit
I changed your select search to use regex:
And changed the value in the OR select to represent a regex OR string:
<option value="search1|search3|search6">search1 or search3 or search6</option>
Kevin
thanks kevin