Can datatables preserve last valid server POST data?

Can datatables preserve last valid server POST data?

hemalhemal Posts: 1Questions: 1Answers: 0
edited September 2014 in Free community support

I have a server-side processing enabled datatable (1.10) implementation. My workflow to reach the problem in hand is as below.

Step 1: User fills in external form with valid data and click a Search button. This sends an Ajax POST request with valid form data. Based on the valid search criteria, data is pulled from DB. This returns a JSON response with data to fill in the table.

Step 2: Now, the user fills in some invalid data in the external form and performs a datatable action such as sort column or paginate to next page.

What's actually happening is the invalid form data is also submitted along with the ajax POST request to sort / paginate.

Expected result: Ignore the LATEST form values for the table sort / paginate action, pass in last valid POST data and retrieve sorted resultset or next page resultset from server-side.

My datatable looks like below.

$("#searchButton").click(
        function() {
            $('#result').dataTable({
                                ...........
                "bServerSide" : true,           // Data retrieved from server-side on paginate and sort actions.
                "ajax": {
                    "url": "search",
                    "type": "POST",
                    "data": function(aoData) {
                        // Set column sort, paginate values in form hidden fields..
                        $('#maxResults').val(aoData.length);
                        $('#offset').val(aoData.start);
                        var sortCol = aoData.order[0].column;
                        var sortDir = aoData.order[0].dir;
                        var sortName = aoData.columns[sortCol].data;
                        $('#sortColumn').val(sortName);
                        $('#sortDirection').val(sortDir);   
                                                
                        return $("#searchForm").serializeArray();   // this is causing issues???
                    },
            },
              ....

I know this is happening because of the $("#searchForm").serializeArray() call I do in Ajax data POST. I'm wondering if there is a better design approach to separate out external form submit and table sort/paginate but still send only LAST VALID FORM DATA in latter 2 actions. Keep in mind that I'm doing server-side processing for every action.

Any idea is much appreciated.

This discussion has been closed.