jQuery DataTables - Filter column by exact match

2019-01-06 16:43发布

Trying to only display exact matches to the search term entered in the search bar.

For instance, I have a search bar that filters by ID#. I want only records that match the exact # entered to display.

So if 123 is entered, I don't want 12345, 91239, etc etc to be displayed. Only 123.

Saw some info about bRegex on the FAQ page, but it's not working for me. Any ideas?

8条回答
\"骚年 ilove
2楼-- · 2019-01-06 17:11

This will give you exact result for a column.

 table.column(i)
 .search("^" + $(this).val() + "$", true, false, true)
 .draw();

ie . search( input , regex, smart , caseInsen )

查看更多
欢心
3楼-- · 2019-01-06 17:12

If you want the exact match from the beginning you can try this code,

    var table = $('#myTable').DataTable()
    $('#filterrow > th:nth-child(2) > input').on( 'keyup change', function () {
        table
        .column( $(this).parent().index()+':visible' )
        .search( "^" + this.value, true, false, true )
        .draw();
    } );
查看更多
登录 后发表回答