Ajax - Server-side processing with pagination

Ajax - Server-side processing with pagination

sattydatasattydata Posts: 1Questions: 1Answers: 0

Hi.
I tried create table with pagination with Ajax - Server-side processing
** I get json data :-
{"recordsTotal":56,"recordsFiltered":4,
"table_data":[{"stud_id":"1","stud_name":"ABC","class":"1"},{"stud_id":"5","stud_name":"PQR","class":"2"},{"stud_id":"6","stud_name":"LMN","class":"3"},{"stud_id":"10","stud_name":"XYZ","class":"1"}] }

** but at the html side it shows
Showing 1 to 4 of 4 entries (filtered from 56 total entries) and data row as "No Matching Records Found"

** My datatable code as :
$('#datatable_info').DataTable({dom: "Bfrtip",
"processing": true,
"serverSide": true,
"ajax": {
url,
"dataSrc": ""
},

        buttons: [{extend: "copy", className: "btn-sm"}, {extend: "csv", className: "btn-sm"},
            {extend: "excel", className: "btn-sm"}, {extend: "pdf", className: "btn-sm"},
            {extend: "print", className: "btn-sm"}], responsive: !0,
        "order": [[0, 'desc']],

"aoColumns": [
{'mData': "table_data.stud_id"},
{'mData': "table_data.stud_name"},
{'mData': "table_data.class"}
],
});

*** I need help for creating table which
1: load data with AJAX Server-side processing
2: pagination which load 10 records at start & load next / previous 10 records on button click previous 1 2 3 .. 10 last

Thank You.

Answers

  • addmoreaddmore Posts: 1Questions: 0Answers: 0

    I do it so.
    `
    lengthMenu: [[10, 25, 0], [10, 25, "Alle"]],
    serverSide: true,
    processing: true,
    searching: false,

            ordering: false,
            deferRender: true,
    
    
            ajax: {
                url: API_URL + '/v1/todo',
                dataSrc: function (json) {
                    var dataReturned = {};
                    dataReturned = json.items;
    
    
                    return dataReturned;
                },
                data: function (d) {
                    d.page = (d.length > 0) ? (d.start / d.length) + 1 : 1;
                    d.maxPerPage = (d.length < 1) ? 999 : d.length;
    
                    delete d.columns;
                    delete d.order;
                    delete d.search;
                }
    
            },
            columns: [
                {
                    data: "id",
                    orderable: false
                },
                {data: "name"},
    
            ]
    

    `

This discussion has been closed.