【发布时间】:2019-10-22 05:27:50
【问题描述】:
我已经在数据表中完成了服务器端处理。 现在我也想做单独的列过滤服务器端处理。
我试过了。
$('#example thead th').each(function () {
var title = $(this).text();
$(this).html(title+' <input type="text" class="col-search-input" placeholder="Search ' + title + '" />');
});
var table = $('#example').DataTable({
dom: 'lfBrtip',
"processing":true,
"serverSide":true,
"ajax":{
"url":"{{route('homeajax')}}",
"dataType": "json",
"type": "POST",
},
"columns":[
{"data":"name"},
{"data":"Position"},
{"data":"office"},
{"data":"age"},
{"data":"start_date"},
{"data":"salary"},
],
initComplete: function(){
this.api().columns().every(function(){
$('input', this.header()).on('keyup change', function () {
if (table.search() !== this.value) {
table.search(this.value,true).draw();
}
});
});
},
paginate: true,
});
它仅适用于一列,但是当我尝试从另一个字段搜索时它不起作用。
当我尝试从另一列输入时,它会显示所有数据,
【问题讨论】:
标签: jquery laravel datatables