disable global search

disable global search

devrusesdevruses Posts: 2Questions: 1Answers: 0

Hello
I am trying to make my own search.
that I succeeded in but the global search overwrite my search.
I made a search that only searched when you typed 3 letters.
Is it possible to turn the global search off and takes my search?

$(document).ready( function () {

     var table = $('#datatable').DataTable({  
        //searching:false ,
        serverSide: true,
        processing: true,
        searchDelay:350,
        ajax: {
            url: "/products/table",
            dataSrc: 'data',
            type: "POST",
        },
        columns: [
         {"data": "id"},
         {"data": "name"},
         {"data": "price"},
         {"data": "width"},
         {"data": "length"},
         {"data": "weight"},
         {"data": "color"},
         {"data": "stocknumber"},

     ]
     });
     $('#datatable_filter input')
     .on('keyup', function () {
                    if (
                       // table.column($(this)).search() !== this.value &&
                        (this.value.length >= 2 || this.value.length === 0 )
                    ) {
                    table
                        //.column($(this).parent().index())
                        .search(this.value)
                        .draw();
                    }
                });

   });

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    edited February 2021 Answer ✓

    Yep, that code is adding to the existing event handler for the input element, so you need to remove the existing one first. Try adding off() into your code, like:

      $('#datatable_filter input')
    .off()
      .on('keyup', function () {
    

    Colin

  • devrusesdevruses Posts: 2Questions: 1Answers: 0

    Yes It works, Thank you for the help.

This discussion has been closed.