Server-Side Paging only paging in one direction.

Server-Side Paging only paging in one direction.

TomG12TomG12 Posts: 2Questions: 1Answers: 0

I'm working a data table that is using server side processing. The paging works, but only in one direction. I am using my own data call to POST the request to the server, as I don't control the service that delivers the data.

The issue is that the data.draw value always increases when clicking any pagination button. If there are 10 pages and I click page 5, it will increase by 1. If I click previous, it will increase by 1. At first I was excited to see the paging work, but shortly realized that it was only working in one direction. :(

Here is the code:

var drawTable2 = function () {

        var table = $('#datatable2').DataTable({
            "serverSide": true,
            "processing": true,
            "paging": true,
            "pagingType": "full_numbers",
            "ajax": dataGetProcess,
            "columns": [
                       { "data": "", "render": renderCheckBox},
                       { "data": "StudentName" },
                       { "data": "Item" },
                       { "data": "Session" },
                       { "data": "Status" }, { "data": "", "render": renderScoreButton }]
        });

    };


var dataGetProcess = function (data, callback, settings) {
        var dataSource = '/api/item/list';
        var postData = {
            "pageNumber": data.draw, //This number is supposed to represent the page that is requested
            "pageLength": data.length, 
            "filters": { 
                "test-Name": "", 
                "a-SessionId": "" }, 
            "sortColumn": "Status", 
            "sortDirection": "DESC" };
        jQuery.post(dataSource, postData, function (rdata) {
            callback({"draw":postData.pageNumber, "data": rdata.StudentItem, "recordsTotal": rdata.RowCount, "recordsFiltered": rdata.RowCount});
        }, 'json');
    };

Any help would be much appreciated.

Thanks,
Tom

Answers

  • TomG12TomG12 Posts: 2Questions: 1Answers: 0

    I'm figured it out.... I thought data.draw was the page number, but there is no page number there is only (data.start / data.length) + 1.

    data.draw is the unique identifier given to a specific ajax call.

    I wasted like 4 hours.

This discussion has been closed.