0
這是我的情景: 我有一個數據表,我以這種方式初始化:jQuery的數據表列的搜索情況下不敏感
invoicesDataTable = $('#invoicesDataTable').DataTable({
processing: true,
serverSide: true,
searchDelay: 1000,
search: {
caseInsensitive: true
},
ajax: {
type: 'GET',
url: '{!! route("admin.invoice.filterData") !!}',
dataSrc: function (response) {
return response.data;
}
},
// aLengthMenu: [ [ 50, 100, 150, 200, -1 ], [ 50, 100, 150, 200, 'All' ] ],
columns: [
{data: 'document_number', name: 'invoices.document_number', orderable: false},
{data: 'document_type', name: 'invoices.document_type', orderable: false},
{data: 'tax_regime', name: 'invoices.tax_regime', orderable: false},
{data: 'auction_id', name: 'auctions.auction_id', orderable: false},
{data: 'business_name', name: 'customers.business_name', orderable: false},
{data: 'total_amount', name: 'invoices.total_amount', orderable: false},
{data: 'datetime_invoice', name: 'invoices.datetime_invoice', orderable: false},
{data: 'actions', name: 'actions', orderable: false, searchable: false}
],
});
初始化我增加了搜索以這種方式每列後:
$('#invoicesDataTable thead th').each(function() {
var title = $(this).text();
$(this).html('<input type="text" style="width:100%;" placeholder="' + title + '" />');
});
invoicesDataTable.columns().every(function() {
var that = this;
$('input', this.header()).on('keyup change', function() {
if (that.search() !== this.value)
that.search(this.value, false, true, true).draw();
});
});
除了不區分大小寫的搜索外,它能正常工作。如果我有一個像「John」這樣的值的列,並且我搜索「john」,那麼它不會向我顯示帶有「John」的那一行。有一種方法可以使它工作? (全球搜索以不區分大小寫的方式完美工作)
你的代碼工作正常,看https://jsfiddle.net/aL3f4w9n/ –