Using two dropdown list for WHERE clause condition load fetch data to datatable

Using two dropdown list for WHERE clause condition load fetch data to datatable

vlsu.tommyvlsu.tommy Posts: 1Questions: 1Answers: 0

Dear Alls,
I am a newbie here. I googled a lot but not find out a solution to solve my problem.
I am using PHP + mysql and I have a mysql table which have many rows (~24.000), if select all then fetch to datatable it cost 20-30 seconds to load / refresh.
So, I want to set two or three dropdown filter (these dropdown selections loaded from other mysql table) before click the Filter button to reduce data and time load to datatable.
Please anybody have a suggestion for this issue? Many thanks!!!!!

Answers

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    You could use "ajax.data" to send additional filters to the server using Editor. Not sure whether you are using Editor.

    In this code snippet I am sending various variables to the server als POST variables to limit the number of values retrieved in case I operate the table in server side mode. In case I operate the table in client side mode the filtering is done on the client but that is something you think will be too slow.

    The values I send to the server are derived from the search input and from two custom buttons. All you would need to do is to create custom buttons or a dropdown or whatevery you need and send the values to the server to limit the number of rows retrieved.

    ajax: {
        url: yourURL',
        type: 'POST',
        data: function ( d ) {   
            if ( serverSideDocSearchPage ) {
                d.fullTextSearchString = d.search.value;
                d.startDateExpired = nMonthsAgo( $('#monthsSelect').val() );
                d.showDeleted = showDeleted ? 1 : 0; //send 1 if true and 0 if false
            }
        }
    },
    

    https://datatables.net/reference/option/serverSide

Sign In or Register to comment.