Pagination & Search not working

Pagination & Search not working

HipHipHipHip Posts: 4Questions: 1Answers: 0

Hi.

I am using server and use following code to get the accurate results

geting parameter values form dropdown

let dp1= document.getElementById("dp1").value;
let dp2 = document.getElementById("dp2").value;

    let paramObjects=  
    {
        "param1": dp1,
        "param2": dp2
    };

var ListTable = $('#mytable').DataTable( 
            {
                "processing": true, 
                "serverSide": true,

                "ajax": 
                {
                    "url" : 'MY URL',
                    "type": "POST",
                    "contentType": "application/json",
                    "data" : function ( d ) 
                    {
                        return JSON.stringify(paramObjects);
                    },
                },
                

                "columns": 
                [
                  
                    { "data": "id" },
                    { "data": "name"},
                    { "data": "company"},
               ],
            });

I am getting perfect results.

But the problem is, pagination & searching is not working.

All entries are showing on first page i.e. 52

Although default per page is 10 and pagination is showing correct 6 pages to be paginated. But all records are showing on front page.

I have tried several examples provided on this forum. But no luck.

Please help

Answers

  • kthorngrenkthorngren Posts: 21,363Questions: 26Answers: 4,956

    The first question is - do you need server side processing?

    With server side processing enabled it is the responsibility of the server script to perform paging, searching and sorting operations and return only the rows to be displayed on the page. With page length of 10 the server script should only return 10 rows. Does your server script follow the Server Side Processing protocol?

    Kevin

  • HipHipHipHip Posts: 4Questions: 1Answers: 0

    Thank you for your reply. Yes I need server side processing.

    Serverside processing with Pagination, searching, filtering works fine. works fine if I removed

    "data" : function ( d )
                        {
                            return JSON.stringify(paramObjects);
                        },
    

    Any thoughts over this.

    Regards

  • kthorngrenkthorngren Posts: 21,363Questions: 26Answers: 4,956

    I don't think using return like that in ajax.data will work. Take a look at the function examples in the docs.

    Kevin

  • HipHipHipHip Posts: 4Questions: 1Answers: 0
    edited February 2022

    Thankyou for reply. But I am following last function

    Submit data as JSON in the request body:

  • kthorngrenkthorngren Posts: 21,363Questions: 26Answers: 4,956

    Right missed that one. The problem is likely in your server script. Use the browser's network inspector to verify the proper parameters are sent in the XHR request. If they are correct then its up to your server script to process them.

    Kevin

  • HipHipHipHip Posts: 4Questions: 1Answers: 0

    I got these in XHR request

    {draw: 0, recordsTotal: 26, recordsFiltered: 26,…}
    data: [{id: "1", cca: "1", name: "NamePerfect", other_name: "FantasticName"},…]
    draw: 0
    recordsFiltered: 19
    recordsTotal: 19
    
  • kthorngrenkthorngren Posts: 21,363Questions: 26Answers: 4,956
    edited February 2022

    That is the XHR response. You will want to look at the request tab and the parameters sent in the request.

    Also note that draw: 0 is incorrect. This is a sequence number and Datatables starts with 1. 0 will not be sent nor expected by Datatables. See the server Side Processing docs for more details. This might be the issue you are seeing.

    Kevin

Sign In or Register to comment.