Find an exact value in a column

Find an exact value in a column

Issues2018Issues2018 Posts: 5Questions: 2Answers: 0

Hello, I have a DataTable like this: http://live.datatables.net/huloxiqo/1/.

When I search for Juan, The table shows me all row that CONTAIN Juan in the field, but I want that the table shows me ONLY the rows which field is Juan.

How can I do it?

Thanks

This question has an accepted answers - jump to answer

Answers

  • MSLtdMSLtd Posts: 56Questions: 5Answers: 4
    edited July 2018 Answer ✓

    Hello @Issues2018 - The data tables search field doesn't seem to have a system for an exact match. You can instead use: search()

    search() api documentation example:

    var table = $('#example').DataTable();
     
    // #myInput is a <input type="text"> element
    $('#myInput').on( 'keyup', function () {
        table.search( this.value ).draw();
    } );
    

    To search for an exact match, the function on key up should be:

    regExSearch = '^\\s' + this.value +'\\s*$';
    table.column(/*columnNo*/).search(regExSearch, true, false).draw();
    
This discussion has been closed.