How to implement local pagination functionality with data from Ajax?

How to implement local pagination functionality with data from Ajax?

whaliimwhaliim Posts: 5Questions: 3Answers: 0

Hi, I would like to be able to get all records from SQL and use "local" pagination (without fetching new records from SQL whenever I select another page (next/previous)).

ServerSide and Pagination works fine when I fetch the data using standard "SELECT". The problem is, I could not use pagination for the data that I obtained via SQL Stored Procedure with ServerSide On.

I understand that I could separate the process (call the Ajax and then draw the table afterwards). However, it would require me to restructure the JS which would be very complex.

Is it possible to achieve this? If yes, how?

Please let me know if you need more information. Thanks in Advance,

Relevant Code:

var table = $('#table').DataTable({
        "searching": false,
        "scrollX": true,
        "scrollY": true,
        "searchDelay": 400,
        "createdRow": function (row, data, dataindex) {
            
        },
        "order": [[0, 'asc']],
        "processing": true,
        "serverSide": true,
        "columns": [
            //columns...
        ],
        "ajax": {
            "url": "Default.aspx/loadStoredProcedure",
            "type": "POST",
            "contentType": "application/json; charset=utf-8",
            "dataType": "text",
            "dataSrc": "data",
            "data": function (d) {
                return JSON.stringify({ parameters: d });
            },
            "dataFilter": function (res) {
                let parsed = JSON.parse(res);
                return parsed.d;
            },
            "error": function (data) {
            }
        },
        "drawCallback": function (settings) {
            //some processing
        },
        "initComplete": function (settings, data) {
            //some processing
        }
    });

Answers

  • kthorngrenkthorngren Posts: 20,354Questions: 26Answers: 4,776

    Sounds like you want to use client side processing instead of server side processing and fetch all the records at initialization. If that's the case then remove the serverSide option, ie, "serverSide": true,.

    Kevin

Sign In or Register to comment.