jQuery的数据表列的搜索情况下不敏感

问题描述:

这是我的情景: 我有一个数据表,我以这种方式初始化: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”的那一行。有一种方法可以使它工作? (全球搜索以不区分大小写的方式完美工作)

+0

你的代码工作正常,看https://jsfiddle.net/aL3f4w9n/ –

做比较都是大写还是小写。

例如:

if (that.search().toLowerCase() !== this.value.toLowerCase()) 

if (that.search().toUpperCase() !== this.value.toUpperCase()) 
+0

这是不正确的答案,这条线不仅使确保文本框中的值已更改。 –