Individual Column Searching (Not Working)
Individual Column Searching (Not Working)
uppkAC
Posts: 4Questions: 1Answers: 0
Help me to resolve this problem. Individual Column Search not work for me
var table = $("#table_unit").DataTable({
processing: true,
serverSide: true,
ajax: {"url": "dataunit/get_data_json", "type": "POST"},
columns: [
{"data": "unit_id"},
{"data": "unit_nama"},
{"data": "unit_kode"},
{"data": "unit_induk"},
{"data": "aksi"},
//{"data": "aksi"}
],
order: [[1, 'asc']],
//language: {"url": "//cdn.datatables.net/plug-ins/1.10.19/i18n/Indonesian.json"},
//Penomoran Baris
columnDefs:
[
{
targets : 0,
orderable : false,
render : function (data, type, row, meta) {
return meta.row + meta.settings._iDisplayStart + 1;
}
},
{
targets : 4,
orderable : false,
}
],
dom: '<"datatable-header"flB><"datatable-scroll-wrap"t><"datatable-footer"ip>',
buttons: {
dom: {
button: {
className: 'btn btn-light'
}
},
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5',
{
extend: 'print',
text: '<i class="icon-printer mr-2"></i> Print table',
className: 'btn btn-light'
}
]
},
initComplete: function () {
this.api().columns().every(function() {
var column = this;
var select = $('<select class="form-control filter-select" data-placeholder="Filter"><option value=""></option></select>')
.appendTo($(column.footer()).not(':last-child').empty())
.on('change', function() {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="'+d.replace(/<(?:.|\n)*?>/gm, '')+'">'+d.replace(/<(?:.|\n)*?>/gm, '')+'</option>')
});
});
}
});
This discussion has been closed.
Answers
There are two possible problems I see because you are using server side processing. This is meant to be a client side search mechanism.
^
prepended and$
appended to the search string. Your server script will need to support regex searching or you need to change the search from.search( val ? '^'+val+'$' : '', true, false )
to.search( val )
to just search for the value.Kevin
Oke , wait , i will try
I have change
.search( val ? '^'+val+'$' : '', true, false )
to.search( val )
but not workingLike this
Since you have server side processing enabled your server script is responsible for performing the search. What are you using for your server script?
Is your server script setup to support column searching?
Here is an example of using the select search with server side processing:
http://live.datatables.net/yehugedi/1/edit
Not all the options are available, only those in the client. Try selecting one of the office locations.
Kevin
i use PHP script like this
i think this script not support column searching, maybe