Exclude fields from default search in datatables server side processing
Exclude fields from default search in datatables server side processing

Hi everyone,
I used ajax server side processing for my datatables. Here is my code.
js code
$('#dt-custom').DataTable({
ajax: $('#dt-custom').data('action'),
columnDefs: [
{ targets: 'hidden', searchable: false, visible: false, className: 'noVis' },
{ targets: 'no-orderable', searchable: false, orderable: false },
],
dom: "<'row'<'col-md-3'l><'col-md-5'f><<'col-mr-6 align-middle'B>>tip",
drawCallback: function() {
$('.dataTables_paginate > .pagination').addClass('pagination-rounded');
},
orderCellsTop: true,
//scrollX: true,
select: { style: 'multi+shift' },
serverSide: true,
stateSave: true,
});
laravel blade code
<table id="dt-custom" class="table table-striped dt-responsive w-100 nowrap" data-action="{{ route('brands.index') }}">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Created At</th>
<th class="no-orderable">Created By</th>
<th class="hidden">id</th>
</tr>
</thead>
</table>
laravel controller code
public function index()
{
// go to the model and get a group of records
if (request()->ajax()) {
$suppliers = DB::table('suppliers')
->whereNull('deleted_at')
->select(['name', 'description', 'created_at', 'created_by', 'id']);
return datatables()->of($suppliers)
->rawColumns([5])
->make(false);
}
// return the view, and pass in the group of records to loop through
return view('suppliers.index');
}
I tried to set class "hidden" for field 'id'. Class 'hidden' applied 'searchable: false', but in default search, I can still search value in field 'id'. I suspected this was because I used ajax server side processing.
How can I prevent 'default search' search value from field 'id'? Please help me. Thank you....
This discussion has been closed.
Answers
The PHP (Laravel) script would need to check for the
searchable
property in the data submitted to the server for each column. This is how our own demo script does it. You'd script would need to do something similar.Allan
Hi Allan,
Thank you for your feedback. However I already got the solution. Just using ->blacklist(['id'])