server side processing issue

server side processing issue

CharleyCharley Posts: 66Questions: 17Answers: 0
edited April 2019 in Free community support

I've configured a datatable to work with server side processing. I'm using ajax and sending the request to a drw call.

I've run into an issue where the datatable isn't handling the data as I expect it when I start paging.

I'm dealing with potentially large datasets (tens of thousands of rows or more). I'm using server side processing to query out only a single page worth of data at a time, and send that back to the client side

On the first page: everything loads correctly
on the second page and subsequent pages: shows as "No matching records found"

I can work around this in my server side code by padding the beginning of the records with X amount of records, where X is the start record. So for example, with a page size of 10

on page 2, 10 blank/throw away records, then the actual 10 records I want to show
on page 3, 20 blank/throw away records, then the actual 10 records I want to show
...
on page 3986, 39850 blank/throw away records, then the actual 10 records I want to show

I feel like this has to be a configuration issue of some sort.

the configuration itself is built with javascript and contains the following (plus some other odds and ends)

var datatablesConfig = {
    "stateSave":stateSave,
    "stateDuration":stateDuration,
    "footerCallback":aggregateFooterCallback,
    buttons: {
        buttons: buttonConfig,
        dom: {
            button: {
                className: 'btn'
            }
        }
    }
}

datatablesConfig.processing = true;
datatablesConfig.serverSide = true;
datatablesConfig.ajax = function (data, callback, settings) {
    dwrFunction(JSON.stringify(data), function (json) { 
        try{
            callback(JSON.parse(json))
        } catch(err){alert("ERROR MESSAGE:" + err)}
    })
}

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765
    Answer ✓

    Not sure I fully understand the problem but does your returned data match the requirements outlined here?
    https://datatables.net/manual/server-side#Returned-data

    Kevin

  • CharleyCharley Posts: 66Questions: 17Answers: 0
    edited April 2019

    the fields that are listed in your link: draw, recordsTotal, recordsFiltered, data (with error optional)

    the return I'm building is

    DataTableResultSet result = new DataTableResultSet(searchRequest, data);
    result.setRecordsTotal(recordsTotal);
    result.setRecordsFiltered(recordsFiltered);
    return result.ToJSON();
    

    searchRequest has the draw value from the request.
    recordsTotal is the result of another sql query that does a count() based on the total number of values in the table + joins that I'm using
    recordsFiltered is a 3rd sql query, a count(
    )

    data is an list of strings, one for each row of data.

    my current workaround is padding data, by prepending x = "start" (from the request) lists with a single empty string in them

    If I just return the 10 actual data rows for page 2 on , it shows "No matching records found"

    padding with extra rows is not much of an issue wheh I'm adding 10 rows for page 2, but it's a bigger deal when I'm padding with 39850 rows for page 3986.

    Followup questions
    1. is my expectation that I only return pageSize rows in data wrong?
    2. am I supposed to pass start back as part of my result?
    3. do I have something else possibly misconfigured?

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765
    Answer ✓

    Start with looking at this example:
    https://datatables.net/examples/server_side/simple.html

    You can look at the Ajax tab to see the response. Do some searches and see what the results look like. Then use the browser's developer tools to see the network XHR response. Then compare the example's network response to yours. What is different?

    Kevin

  • CharleyCharley Posts: 66Questions: 17Answers: 0

    I found my issue, it was in the toJson code; I had a holdover piece of coder that was doing pagination in the code instead of the sql. Finally found it when looking at the json actually coming from the server.

This discussion has been closed.