JavaYouth JavaYouth - 7 months ago 257
Javascript Question

Server Side Pagination with jQuery Data Tables plugin

How can I achieve server side pagination using data table? Currently, on load of page I am initializing the data table & filling the table with Data (JSON) coming from database via Java Spring controller. I am making an Ajax call by passing search criteria in query string. Since we have hundreds of thousands of records, we have planned for server side pagination to improve performance.

For this the backend service developer has given me a service that gives me the per page records but takes inputs like PAGE NUMBER, NO OF PAGE RECORDS, SORT ORDER, SORT COLUMN.

I have to override data table implementation to pass these to service via Ajax request query string. I don't know if there is a way to achieve this.

Answer

How can I achieve server side pagination using data table?

For more info check out the documentation

$(document).ready(function() {
    $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "../server_side/scripts/server_processing.php"
    } );
} );

I would advise you to take a look at the docs again.

When making a request to the server using server-side processing, DataTables will send the following data in order to let the server know what data is required I would not copy all the parameters but only few of them here:

start, length, order[i][column]

those are the ones you are after I suppose.

KEEP IN MIND:

Once DataTables has made a request for data, with the above parameters sent to the server, it expects JSON data to be returned to it, with the following parameters set:

and you want to take a look at the properties yourself, in order not to make this post too long.