【问题标题】:datatables default regex to search only start数据表默认正则表达式仅搜索开始
【发布时间】:2016-11-16 11:24:10
【问题描述】:

您好有如下数据表的 java 脚本,如何定义它以便只对起始值进行搜索,例如:[hello, 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" ]]
       });

【问题讨论】:

标签: javascript jquery regex datatables


【解决方案1】:

查看文档: https://datatables.net/examples/api/regex.html 我认为 filterColumn 功能就是您要寻找的功能。 我希望这会有所帮助。

格鲁斯

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') );
} );
} );

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2014-05-13
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      • 2023-04-10
      • 2013-08-16
      相关资源
      最近更新 更多