One search request for all individual column filters?

One search request for all individual column filters?

marcelvmarcelv Posts: 27Questions: 6Answers: 0

Hi,

I have setup individual column filtering for my datatable.

Then I search on keyPress of the return/enter button like this:

$jq( 'input', this.header() ).on( 'keydown', function (ev) {
                 if (ev.keyCode == 13) { //only on enter keypress (code 13)
                    that
                        .search( this.value )
                        .draw();
                 } else {
                     that
                        .search( this.value );
                 }
            } );

The idea of this is to set the search values on every change in whatever search input, but to search only when enter is pressed. The search is working, but the problem is, as soon as I press enter and the table draw function is called, there are like 50 requests posted to the server. Probably because I call that.search(this.value) on every change.

Why are there so many requests generated? I want one request, with all the searches across the different input fields. How to accomplish that? Obviously this is a performance killer.

Is there something else then that.search to modify the search parameters, but to prevent a request for every single that.search which is set.

To me this sounds like a very basic thing, but I searched everywhere. Seems like on datatables 1.9 this was possible via a plugin someone made, but it does not work on 1.10.

Alternative for me would be all the search inputs for every column, and one seperate search button. Then to execute the search only when someone presses that button. And on press I don`t want 50 requests to be sent, but just one requests containing all the searches. But I assume if there is a solutions for this, there must also be a solutions for my problem.

Hopefully someone can help me soon since it`s really blocking my further development.

Thanks a lot!

Answers

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67
    edited August 2015

    You can try my yadcf plugin for datatables, it got 10 filter types / integration with third party plugins / support server side config, and many other goodies, see relevant showcase example

  • marcelvmarcelv Posts: 27Questions: 6Answers: 0

    Thanks will look into it, so no native datatables solution?

  • marcelvmarcelv Posts: 27Questions: 6Answers: 0

    @daniel_r, do you have a direct link to demo / example of multiple search fields, but where request to server is only fired on press of enter or on click of a search button? So no direct search after every change or for every column, but multiple search inputs and one search action?

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67

    The following might be a bingo for you, see the externally_triggered: true page

  • marcelvmarcelv Posts: 27Questions: 6Answers: 0
    edited August 2015

    Hi, thanks, that looks like what I was looking for. But in the meanwhile I already found the source of my problem. My code was right en worked, but it was wrapped inside datatables.columns.each() which was causing every request being fired many times (for every column).

    So my new code is:

         searchRowRef = $jq("tr#searchRow");     
            $jq( 'input', searchRowRef ).on( 'keydown', function (ev) {
                attindex = $jq.inArray('description',jsarr); //my own array of columns
                
                if (ev.keyCode == 13) { //only on enter keypress (code 13)
                    oTable
                        .column( attindex ).search( this.value )
                        .draw();
                 } else {
                    oTable.column( attindex ).search( this.value );
                 }
            } );
    

    This code just fires the search when the user presses the enter / return button. They do not have to enter for every single column because I set the search on every keypress.

This discussion has been closed.