Server Side Processing 1 Million Records Resulting in Error

Server Side Processing 1 Million Records Resulting in Error

ProgrammingWithRandyProgrammingWithRandy Posts: 5Questions: 2Answers: 0
edited May 2017 in Free community support

Here is my datatables setup

JS:

<script type="text/javascript">
    $(document).ready(function () {
        $('#users').DataTable({
            "processing": true,
            "serverSide": true,
            "columns": [
                {"data": "id"},
                {"data": "report_type"},
                {"data": "record_date"},
                {"data": "name"},
                {"data": "insert_time"}
            ],
            "ajax": {
                url: 'source.php',
                type: 'POST'
            }
        });
    });
</script>

source.php:

    $response = array(
        "iTotalRecords" => $recordsTotal,
        "iTotalDisplayRecords" => 1000,
        "draw" => intval($draw),
        "recordsTotal" => $recordsTotal,
        "recordsFiltered" => $recordsFiltered,
        "data" => $data
    );
    echo json_encode($response);

When I only have a few thousand records, everything works fine (there is more code in source.php but I know it is accurate since the page works with a small dataset). However, once I up that number to 1 million, an error occurs:

DataTables warning: table id=users - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

Any ideas what the issue is? Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Did you follow the instructions in the tech note you linked to? What is the response from the server since it isn't valid JSON?

    Allan

  • ProgrammingWithRandyProgrammingWithRandy Posts: 5Questions: 2Answers: 0

    I was using a server-side approach but still returning all records at once - I think this resulted in a json array that was too large and got cut off. I took a new approach using ssp.class.php, then re-wrote SSP::simple as a custom function in order to return my results. Everything is working fine now, thanks!

  • katybirdkatybird Posts: 1Questions: 0Answers: 0

    Hi, could you share your custom function?

This discussion has been closed.