Unable to Get Exact Match in datatable

Unable to Get Exact Match in datatable

rit_netsysrit_netsys Posts: 5Questions: 2Answers: 0
edited March 2019 in Free community support

I am trying to achieve Exact Search in the Datatable. Presently I am passing a value to 'Search' field from another Jquery function. This is working quite fine. Now I am trying to achieve the EXACT SEARCH in the Datatable. Here is my code block --

$(document).ready(function () {
        var query = getUrlVars()["query"];
            var table = $('#q2').removeAttr('width').dataTable({
        "search": {"search": query, 
                 "regex": false,
                 "smart": false},
                "ordering": true,
                "language": {"zeroRecords": "No records to display"},
                ajax: 'logapi.php?query=query_02',
                fixedHeader: true,
                deferRender: true,
                scroller: true,
                processing: 'Loading...',
                autowidth: true,
                responsive: false,
                orderClasses: false,
        columnDefs: [{ width: 100, targets: 0 }],
        fixedColumns: true

But while trying to pass the value "ART_SUP_PACK" to search field, it is returning 2 rows contains "ART_SUP_PACK" & "ART_SUP_PACK_V" i.e. Exact Search not working as expected.

What I am doing wrong here? Am I missing something?

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @rit_netsys ,

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • rit_netsysrit_netsys Posts: 5Questions: 2Answers: 0
    edited March 2019

    Hi @colin ,

    I Tried like this. But this is not working. Am I doing something wrong?

    $(document).ready(function () {
                var query = getUrlVars()["query"];
                var table = $('#q2').removeAttr('width').dataTable({
                    "search": {"search": query, 
                                "regex": true,
                                "smart": false},
                    "ordering": true,
                    "language": {"zeroRecords": "No records to display"},
                    ajax: 'logapi.php?query=query_02',
                    fixedHeader: true,
                    //scrollY: 300,
                    //scrollX:        true,
                    //scrollCollapse: true,
                    deferRender: true,
                    scroller: true,
                    //stateSave: true,
                    processing: 'Loading...',
                    autowidth: true,
                    responsive: false,
                    orderClasses: false,
                    columnDefs: [{ width: 100, targets: 0 }],
                    fixedColumns: true
    
                });
                //table.column(1).search("(^"+query+"$)",true,false).draw();
                $('.dataTables_filter input').unbind().bind('keyup', function() {
                var searchTerm = this.value.toUpperCase(),
                regex = '\\b' + searchTerm + '\\b';
                table.rows().search(regex, true, false).draw();
    })
     });
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @rit_netsys ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • rit_netsysrit_netsys Posts: 5Questions: 2Answers: 0

    Hi @Colin,

    I tried with live.datatables.net. But unable to replicate the scenario exactly. Can you help me out? Here is the edited link - http://live.datatables.net/titobage/1/edit

  • kthorngrenkthorngren Posts: 21,673Questions: 26Answers: 5,018

    You are getting this error in the console:
    Uncaught ReferenceError: getUrlVars is not defined

    Kevin

This discussion has been closed.