DataTables Global Search With Regex
DataTables Global Search With Regex
I am using Yajra Data Table in my Laravel Application. Here is the code snippet.
<table id="smTable" class="table">
<thead class="bg-light w-100" style="">
<tr style="">
<th class="ant-table-cell hideID noVis">id</th>
<th class="ant-table-cell">Sr</th>
<th class="ant-table-cell">educaton</th>
<th class="ant-table-cell">gender</th>
</tr>
</thead>
<tbody class="hidetrID" style="height:100px">
<tr class="id odd">
<td class="sorting_1">1</td>
<td class=" noVis">1</td>
<td>Graduate</td>
<td>FEMALE</td>
</tr>
<tr class="id even">
<td class="sorting_2">2</td>
<td class=" noVis">2</td>
<td>Associate Grduate</td>
<td>MALE</td>
</tr>
</tbody>
</table>
option_table = $('#smTable').DataTable({
destroy: true,
processing: true,
serverSide: false,
ajax: {
url: "{{ route('view-smart-search-table') }}",
type: "GET",
},
createdRow: function(row, data, dataIndex) {
$(row).addClass('id');
},
initComplete: function(settings, json) {
// $('#searchKeyword').trigger('input');
},
columns: [{
data: 'id',
name: 'id',
searchable: false
},
{
data: 'DT_RowIndex',
name: 'DT_RowIndex',
searchable: false
},
{
data: 'education',
name: 'education'
},
{
data: 'gender',
name: 'gender',
},
],
dom: 'Blfrtip',
columnDefs: [{
targets: 1,
className: 'noVis',
}],
buttons: [{
extend: 'colvis',
collectionLayout: 'fixed two-column',
text: 'List of Visible Coloumn Names in Current Table(Click to Deselect a Coloumn)',
columns: ':not(.noVis)'
}]
});
search string: Gradute
Case 1: **Now that when i search for **'Graduate' the result displayes the both record (since string matches with both record) so understood. I wanted that result.
search string: gradute male
**Case 2: ** I search for 'gradute male' result displays the both record, again I wanted this result.
**Issue to Resolve: **
**Case 3: ** What if I want to search for candiate with education 'Gradute' only not for associate graduate even if string matches with associate graduate. and also search string 'MALE graduate' must bring me the MALE GRADUATE candiate only. regardless of string matches with female & associate gradute too.
Please Note: There are other coloumns too and search 'male cl10 graduate teamA' is fetching me correct record, but now I want to search some coloumns specifically like MALE & Gradute example with this global search. Thanks
Answers
See if this example helps with regex searching.
Kevin