jQuery DataTables - Filter column by exact match

前端 未结 9 2429
感动是毒
感动是毒 2020-11-27 18:06

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 m

相关标签:
9条回答
  • 2020-11-27 18:42
    $(document).ready( function() {
        $('#example').dataTable( {
            "oSearch": {"bSmart": false}
        } );
    } )
    

    Try using the bSmart option and setting it to false

    From the documentation

    "When "bSmart" DataTables will use it's smart filtering methods (to word match at any point in the data), when false this will not be done."

    UPDATE

    I found this:

    oSettings.aoPreSearchCols[ iCol ].sSearch = "^\\s*"+'1'+"\\s*$";
    oSettings.aoPreSearchCols[ iCol ].bRegex = false;
    oSettings.aoPreSearchCols[ iCol ].bSmart= false;
    

    at this link http://www.datatables.net/forums/discussion/4096/filtering-an-exact-match/p1

    looks like you can set bSmart and bRegex per column as well as specifying a manual regex per column.

    0 讨论(0)
  • 2020-11-27 18:44
    $(document).ready(function() {
        tbl = $('#example').dataTable();
        tbl.fnFilter("^" + filter_value + "$");
    });
    

    Where filter_value is the string entered in the filter field.

    0 讨论(0)
  • 2020-11-27 18:45

    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 )

    0 讨论(0)
提交回复
热议问题