Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82607

Datatables serverSide processing not working as intended, more like client side

$
0
0

Hello!

I've encountered a problem with my datatables implementation. I'm currently trying to load a almost 50 000 results for my datatables and I used serverSide processing since client side takes a long time. I'm using datatables cdn 1.10.

Now as much as I understood, server side is used when I want to avoid loading all of the data at once, but it makes a new ajax request with each page call, and loads only the necessary data, reducing the load time significantly.

My problem is that with server side enabled, my datatables make a new request for each page, but they load ALL DATA every time and go into a timeout and die. I'm not sure where the problem is, so any help would be appreciated

This is how I use my datatables.
JS

    $('#my-table').DataTable({
        serverSide: true,
        processing: true,
        ajax: {
            url: '/user-comments',
            method: 'POST',
        },
        columns: [
            {
                data: "rating",
                render: function ( data, type, full, meta ) {
                    if (full.rating == 1)
                        return 'LOVE';
                    else
                        return 'HATE';
                }
            },
            {data: "comment"},
            {data: "email"},
        ],
        pageLength: 50,
        fnDrawCallback: function( ) {
            $('[data-toggle="tooltip"]').tooltip();
        },
        language: {
            processing: "Loading data...",
            emptyTable: "No data available!"
        }
    });

PHP


if ($this->request->isAjax()){ $resultSet = Model::find(); $array = []; foreach($resultSet as $res){ //Note that this is an example of php usage, can't put the entire code do to security reasons, but the data provided to array is fine $array[] = $res->toArray(); } $dataTables = new DataTable(); $dataTables->fromArray($array)->sendResponse(); $this->view->disable(); }

Thanks for the replies in advance!
Best regards.


Viewing all articles
Browse latest Browse all 82607

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>