This topic contains 18 replies, has 2 voices, and was last updated by Jai Jai 1 week ago.

My m-datatable cannot paginate


  • renkawan
    Participant

    Posts: 14
    Member Reply #17202

    Hi 🙂

    I made my m-datatable with “remote” type, when I tried your source from https://keenthemes.com/metronic/preview/inc/api/datatables/demos/default.php, and use your code here https://keenthemes.com/metronic/preview/assets/demo/default/custom/components/datatables/base/data-ajax.js to load, the table run flawlessly, pagination works well.

    Then I tried my self with my own data and with your response structure, I don’t know why my table show all result in one page, pagination not work. I attached files for my response and my code as well.

    Please help, thanks

    • This topic was modified 4 weeks ago by  renkawan. Reason: reupload code for load
    Attachments:
    You must be logged in to view attached files.
    Jai
    Jai
    Keymaster

    Posts: 2128
    Support Staff Reply #17218

    Hi 🙂

    Using remote data source, the pagination should be handled in the remote API.

    Please check our demo backend API script, in docs/api_reference/, written in PHP.

    Thanks


    renkawan
    Participant

    Posts: 14
    Member Reply #17478

    I did pagination on my server, but I got another problem now, the pagination info (displaying data … of …) not working as your example. I don’t know why, please help. Please see this screenshot : https://ibb.co/neN3Ty


    renkawan
    Participant

    Posts: 14
    Member Reply #17479

    one more, I have set pageSize: 20, but  I still got 10 data shown each page >_<

    saveState: {
    cookie: false,
    webstorage: false
    },
    pageSize: 20,
    serverPaging: true,
    serverFiltering: true,
    serverSorting: false

    params generated:
    pagination[page]: 1
    pagination[pages]: 363
    pagination[perpage]: 10
    pagination[total]: 3623
    query:

    • This reply was modified 2 weeks, 2 days ago by  renkawan. Reason: completing info
    Jai
    Jai
    Keymaster

    Posts: 2128
    Support Staff Reply #17537

    Hi 🙂

    Have you properly recompile the assets using gulp?

    Can you try to clear browser cache?

    About the (displaying data … of …)  issue, in your backend does it properly count the meta?

    Thanks


    renkawan
    Participant

    Posts: 14
    Member Reply #17545

    I think my meta data was right, here is :


    $pagination = $_REQUEST["pagination"]; // From m-datatable
    $data["meta"] = array(
    "page" => $pagination["page"],
    "pages" => round($my_total_data / $pagination["perpage"]),
    "perpage" => $pagination["perpage"],
    "total" => $my_total_data
    );

    Any advice or example that would help me?
    Thanks

    Jai
    Jai
    Keymaster

    Posts: 2128
    Support Staff Reply #17550

    Hi 🙂

    Our sample server script is in here docs/api_reference/,

    Can you send your full backend server script? Let see if we can find something

    Thanks


    renkawan
    Participant

    Posts: 14
    Member Reply #17564

    Hi, please look here for response : https://ibb.co/bMcd0d

    And my script please look here : https://pastebin.com/3S14fYDk

    Thanks

    Jai
    Jai
    Keymaster

    Posts: 2128
    Support Staff Reply #17565

    Hi 🙂

    Can you try to set this option to true?

    serverPaging: true,
    serverFiltering: true,
    serverSorting: true

    Thanks


    renkawan
    Participant

    Posts: 14
    Member Reply #17567

    I revised the script from serverSorting: false into serverSorting: true, still same. here my latest screenshot result : https://ibb.co/h90kfd

    Please if any advice, thanks Jai

    Jai
    Jai
    Keymaster

    Posts: 2128
    Support Staff Reply #17573

    Hi 🙂

    Can you check if the data count exactly received 20 items, same number as perpage?

    Thanks


    renkawan
    Participant

    Posts: 14
    Member Reply #17615
    This reply has been marked as private.
    Jai
    Jai
    Keymaster

    Posts: 2128
    Support Staff Reply #17641

    Hi 🙂

    Can you pass another key “pages” with total pages available on the server?

    “meta”: {
    // pagination
    “page”: 1,
    “pages”: 35,
    “perpage”: 10,
    “total”: 350,
    // sorting
    “sort”: “asc”,
    “field”: “RecordID”
    },

    Please check sample backend script;

    /docs/api_reference/datatables/demos/default.php

    You can count it like this;
    $pages = ceil($total / $perpage);

    Thanks

    • This reply was modified 1 week, 3 days ago by Jai Jai.

    renkawan
    Participant

    Posts: 14
    Member Reply #17669

    Unfortunately still same, I’ll try analyze more then, and I’ll give you the updates soon. Thanks

    Jai
    Jai
    Keymaster

    Posts: 2128
    Support Staff Reply #17699

    Hi 🙂

    How is it going? Can you verify in devtools that the “pages” meta is there?

    Thanks

Tagged: 

You must be logged in to reply to this topic.