improved reset of input tfoot value

improved reset of input tfoot value

rivaldidrivaldid Posts: 55Questions: 6Answers: 2

I'm using datatable with the serverside pagination, and my issue is about to reset the individual search filters implemented by input on the tfoot with placeholder label.
Now, I got tons of call to the backend on every bunch of search. I have developed buttons which trigger multiple input filling to achieve specified purpose on a huge table of database. About 170k record with about 50 columns.
I always noticed slow response when trigger this buttons, and looking on developer area of the browser I just noticed thias tons of call to the backend wich are really not usefull, example to trigger 4 search by keyup event I have a draw number which increment from 3 to 105 and 201 and 315, So 100 of call just to do few searches not surely 100 searches.
Everytime I trigger a new search I do a full reset of all input boxes with this function:

    function mycustom_init_reset() {
        $('#presentation thead th').each( function() {
            var title = $(this).text();
            $(".filter_"+title.replace(/\s/g, "")).val('').trigger('keyup');
        });
    };

I think I'm triggering uselessly all the input boxes also if they don't host any value.
Any help to check with and if-then statement if this box is been used, I can't just reset it's value to empty without trigger an action on the backend but I guess I can just test if is the case to do it.
I have tried with object .lenght but I have not achieved my goal. Any better idea?

Replies

  • kthorngrenkthorngren Posts: 14,167Questions: 25Answers: 3,339

    Instead of using .trigger('keyup') to force the search use columns().search() with an empty string to clear the server side searches in one request. For example:

    function mycustom_init_reset() {
        table.columns().search( "" ).draw();
        $('#presentation thead th').each( function() {
            var title = $(this).text();
            $(".filter_"+title.replace(/\s/g, "")).val('');
        });
    };
    

    Where table is in instance of the Datatables API.

    Kevin

  • rivaldidrivaldid Posts: 55Questions: 6Answers: 2

    Thank you Kevin, you saved my application!

Sign In or Register to comment.