Server-side Paging widget always page 1

Server-side Paging widget always page 1

toomanyloginstoomanylogins Posts: 16Questions: 4Answers: 0
edited January 7 in DataTables 2

I am returning the start and length in the json following the ajax request but the paging widget is always 1 and records always Showing 1 to..... however the records displayed are the correct selection. I have read the manual https://datatables.net/manual/server-side but cant see any other param which sets the paging widget ? I am confused about what the draw param actually does. Is it the page number ?

In config I have
serverSide: true,
paging: true,

Answers

  • toomanyloginstoomanylogins Posts: 16Questions: 4Answers: 0

    I have fixed it with
    stateSave: true,

    However I dont understand why this is needed If I am passing the start value back in the json? I must be missing something

  • toomanyloginstoomanylogins Posts: 16Questions: 4Answers: 0

    Not fixed as saveState no good if returning to the list from different queries. Would appreciate if someone could clarify if paging widget is supposed to be update via the .start param ie if page length is 15 and start is 30 then its page 3 on the widget
    Thanks

  • kthorngrenkthorngren Posts: 21,554Questions: 26Answers: 4,994
    edited January 7

    I have fixed it with
    stateSave: true,

    That's strange. That shouldn't be a fix for the paging information being correct.

    I am confused about what the draw param actually does. Is it the page number ?

    No. It is a sequence number. If draw: 1 is sent then Datatables expects the response to have draw: 1. Another example is if Datatbles sends a request with draw: 2 then draw: 3 before the response for draw: 2 is returned it will ignore all other responses until draw: 3 is received.

    Maybe you can start by using the browser's network inspector and post the JSON request and response when going to page 2. A link to a test cae showing the issue is even better.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • toomanyloginstoomanylogins Posts: 16Questions: 4Answers: 0

    Thanks for reply, This is the json returned to the list page after viewing a detail page. The selection of records etc is all correct it is just the paging widget. If this is insufficient I'll have a look at the debugger as this is not public. In example below I am expecting the widget to show page 6 ?

    {
    "draw": 2,
    "length": 15,
    "recordsTotal": 102,
    "recordsFiltered": 102,
    "start": 75,
    "data": [
    [
    "3D3E5AFAA1AFD647A8264CAF31AD2B87",
    "<input type='checkbox' class='form-check-input' onclick=\"selectPost(this.checked,'3D3E5AFAA1AFD647A8264CAF31AD2B87')\"/>",
    "<a href=\"#\" onclick=\"ltgFormAction('project-task-detail.html?action=edit&record=3D3E5AFAA1AFD647A8264CAF31AD2B87');\">1190 Region List Bugs</a>",
    "My Company",
    "",
    "2023-10-30",
    "0000-00-00",
    "import",
    "",
    "DCCA592AE15DB247B07ADAB5F8E4185C",
    null,
    1190
    ],

    Cheers, Paul

  • toomanyloginstoomanylogins Posts: 16Questions: 4Answers: 0

    I have also tried without returning the length and start as according to docs not part of json . Same result. So still confused how to set the paging widget to correct page number on return ?

  • kthorngrenkthorngren Posts: 21,554Questions: 26Answers: 4,994

    That looks correct, except you don't need to return the start parameter. It won't hurt anything as it will be ignored. See the SSP response parameters docs for details.

    If I understand correctly you are seeing the info element displaying Showing 1 to 15 of 102 entries instead of Showing 76 to 91 of 102 entries.

    Also you are seeing the 1 button in the paging element as selected instead of 6. Do you all the paging buttons?

    However you are seeing the correct data, records 76 - 91, displayed on the page.

    Is all this correct?

    That isn't normal and I don't remember hearing of this issue before. This example behaves correctly.

    Possibly you have an old version of Datatables. What version are you running?

    Do you see other XHR requests sent after the above response? Possibly an event is firing causing another request to be sent.

    Kevin

  • kthorngrenkthorngren Posts: 21,554Questions: 26Answers: 4,994

    So still confused how to set the paging widget to correct page number on return

    This should happen automatically in the Datatables code. That's why it is a strange problem. You could PM Allan with connection details if you don't want to make a public test case..

    Kevin

  • toomanyloginstoomanylogins Posts: 16Questions: 4Answers: 0

    Even tried setting page within initComplete
    let pageNum = parseInt(ltgObj('.page').val());
    table.page(pageNum);

    Widget is always page 1

    I used the download builder as follows it was 2023 by look of it.

    /*
    * This combined file was created by the DataTables downloader builder:
    * https://datatables.net/download
    *
    * To rebuild or modify this file with the latest versions of the included
    * software please visit:
    * https://datatables.net/download/#bs4/dt-1.13.8/e-2.2.2/b-2.4.2/b-colvis-2.4.2/date-1.5.1/sl-1.7.0
    *
    * Included libraries:
    * DataTables 1.13.8, Editor 2.2.2, Buttons 2.4.2, Column visibility 2.4.2, DateTime 1.5.1, Select 1.7.0
    */

    /*! DataTables 1.13.8
    * ©2008-2023 SpryMedia Ltd - datatables.net/license
    */

    I will download again see if it sorts it out.
    Thanks

  • kthorngrenkthorngren Posts: 21,554Questions: 26Answers: 4,994

    I will download again see if it sorts it out.

    Using the above link will upgrade you to all the latest Datatables code. Which is a good thing but you may have other changes needed for it to work. See the Datatables 2.1 thread for details.

    You can use this link to get the 1.13 code but it is not supported anymore with the release of DT 2.0.

    Again you shouldn't need to do anything with the paging. Here is a simple test case with 1.13.8:
    https://live.datatables.net/yaroyala/75/edit

    It works as expected. There is something specific to your page causing the issue. Maybe try a basic page with a simple Datatables config, like my example, to see if it works then go from there. Let us know if this works.

    Kevin

  • toomanyloginstoomanylogins Posts: 16Questions: 4Answers: 0

    If I understand correctly you are seeing the info element displaying Showing 1 to 15 of 102 entries instead of Showing 76 to 91 of 102 entries.

    Yes

    Also you are seeing the 1 button in the paging element as selected instead of 6. Do you all the paging buttons?

    Yes

    However you are seeing the correct data, records 76 - 91, displayed on the page.

    Yes

    The records are correct because it is a new selection created server-side. This is where I am confused because the table is re-initialised therefore dont see how I can set the correct page.

    From the docs it would seem I have use the saveState Callback options.
    Thanks

  • toomanyloginstoomanylogins Posts: 16Questions: 4Answers: 0

    Fixed I am using this option to set the pageNum when table is initialised. Needed to add draw(false) to get it to work.

    table.page(pageNum).draw(false);

    Thanks for help.

  • kthorngrenkthorngren Posts: 21,554Questions: 26Answers: 4,994

    This is where I am confused because the table is re-initialised therefore dont see how I can set the correct page.

    What do you mean the table is reinitialized. Are you calling something to recreate the table?

    From the docs it would seem I have use the saveState Callback options.

    stateSave does not influence the page displayed via server side processing. It only influences the page displayed on initialization. If you go to page 6 leave the page then reopen the page then page 6 will be requested from the server. Still the paging element should have button 6 active not 1.

    As I said try a basic config like my example to see if it works then go from there.

    Kevin

  • kthorngrenkthorngren Posts: 21,554Questions: 26Answers: 4,994

    Or maybe you can update my test case to show the issue you are having. The issue doesn't seem to be data specific.

    Kevin

  • kthorngrenkthorngren Posts: 21,554Questions: 26Answers: 4,994

    OTOH if you have stateSave enabled and always want start on page 1 then use option stateLoadParams to force page 1.

    Again more info is needed to help further troubleshooting. Maybe post your full Datatables code.

    Kevin

  • kthorngrenkthorngren Posts: 21,554Questions: 26Answers: 4,994
    edited January 7

    table.page(pageNum).draw(false);

    That doesn't explain why you are seeing the data for other pages. Maybe I'm misunderstanding that part of the problem description. Looks like I totally didn't understand your solution or issue. Thought you were clicking a page number but the active page always showed as 1.

    Glad its resolved.

    Kevin

Sign In or Register to comment.