Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DDSameera's avatar

set page number via on external URL

I want to set datatable page through the url .how could i do that ? https://datatables.net/

See this

https://snipboard.io/0MV27T.jpg

0 likes
1 reply
Nakov's avatar

@ddsameera you can add this callback function to your DataTable initialization config.

"initComplete": function (settings, json) {
    let api = new $.fn.dataTable.Api(settings);
    let url = new URL(window.location.href);
    let page = url.searchParams.get("page");
    if (page !== null) {
        api.page(parseInt(page) - 1).draw(false);
    }
}

So from the code above the expected param is ?page=10 and I do parseInt(page) - 1 as the pagination is 0 indexed, so if you got to page 1 it will show the first page and so on..

Please or to participate in this conversation.