2016-11-16 55 views
0

喜有数据表的Java脚本如下,如何定义它,以便搜索是启动值,例如只是做:你好,hello_all,all_hello]在那里,我的搜索键单词是“hel”我应该得到[hello,hello_all]的过滤器。数据表默认的正则表达式只搜索开始

$('#example').DataTable({ 
      data: new_data, 
      dom: '<"top"fB>rt<"bottom"ipl>', 
      buttons:['csv'], 
      search :{"bSmart": false, 
         "regex":true}, 
      columns: [ 
       { title: "Action" }, 
       { title: "Input" }, 
       { title: "State" }, 
       { title: "Completed" }, 
       { title: "Project" }, 
      ], 
      "order": [[ 3, "desc" ]] 
     }); 
+0

[jQuery的数据表搜索可能的复制 - 设置搜索过滤器以获得只匹配,开始像搜索值](http://stackoverflow.com/questions/29359594/jquery-datatables-search-set-search-filter-to-get-only-matches-that-starts-lik) –

回答

0

参见文档: https://datatables.net/examples/api/regex.html 的filterColumn功能是你在寻找什么,我认为。 我希望有所帮助。

Gruesse

function filterGlobal() { 
$('#example').DataTable().search(
    $('#global_filter').val(), 
    $('#global_regex').prop('checked'), 
    $('#global_smart').prop('checked') 
).draw(); 
} 

function filterColumn (i) { 
$('#example').DataTable().column(i).search(
    $('#col'+i+'_filter').val(), 
    $('#col'+i+'_regex').prop('checked'), 
    $('#col'+i+'_smart').prop('checked') 
).draw(); 
} 

$(document).ready(function() { 
$('#example').DataTable(); 

$('input.global_filter').on('keyup click', function() { 
    filterGlobal(); 
}); 

$('input.column_filter').on('keyup click', function() { 
    filterColumn($(this).parents('tr').attr('data-column')); 
}); 
}); 
0

我有一个单独的搜索字段中的一列,这里是我的解决方案开始,与搜索:

vm.searchForLocation = function() { 
    vm.dtInstance.DataTable.column(2) 
     .search("^"+vm.locationCode, true, false) 
     .draw(); 
}