[英]jQuery DataTable exact match
I have this jQuery datatable in place:我有这个 jQuery 数据表:
var $dataTable = $('#example1').DataTable({
"ajax": serviceUrl,
"iDisplayLength": 25,
"order": [[ 2, "asc" ]],
"scrollY": 600,
"scrollX": true,
"bDestroy": true
});
I also have this CHANGE event happening when the user selects an option in a dropdown:当用户在下拉列表中选择一个选项时,我也会发生这个 CHANGE 事件:
$('#serviceload').on('change',function()
{
$dataTable.columns(1).search( this.value ).draw();
});
I need to be able to alter the CHANGE event so that it searches the DataTable for the exact match in the dropdown.我需要能够更改 CHANGE 事件,以便它在下拉列表中搜索 DataTable 中的完全匹配项。
For example, the v has 2 services called SERV and SERV_ONE.例如,v 有 2 个服务,称为 SERV 和 SERV_ONE。 In the dropdown, both SERV and SERV_ONE are available for the user to choose, but if the user chooses SERV, the datatable filters for SERV and also displays the records for SERV_ONE.在下拉列表中,SERV 和 SERV_ONE 都可供用户选择,但如果用户选择 SERV,数据表将过滤 SERV 并显示 SERV_ONE 的记录。 But when SERV_ONE is chosen, the DataTable only displays the records for SERV_ONE.但是,选择Serv_one时,DataTable仅显示Serv_one的记录。
See this example for proper use of drop-down filters.请参阅此示例以正确使用下拉过滤器。
$('#serviceload').on('change keyup', function(){
var val = $.fn.dataTable.util.escapeRegex($(this).val());
$dataTable
.columns(1)
.search( val ? '^' + val + '$' : '', true, false )
.draw();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.