Issues setting initial page using Server Side

Issues setting initial page using Server Side

DzyannDzyann Posts: 12Questions: 3Answers: 0
edited May 2018 in Free community support

I have a rather complex setup I can not fully reproduce here, but basically I set the initial page like I have seen in the documentation but is not working properly. I am retrieving the data from the server, I use the information that i receive in the ajax function. For some reason I get always 0 as the start position.

Paging manually (if the user clicks on the page) work perfectly, I get the correct start value, so it has something to do with the initial setup:

table.page(page);
//here I do additional configuration, like setting some filters. I get the same issue if I dont set filters however.
table.draw('page');

Yet when I don't get the proper start number on the ajax call:

  var ajaxConfig = {
        "url": dataUrl,
        async: false,
        type: "POST",
        "data": function (d) {
            //Do ajax call.

d.start is 0 although the page is 3.

I even tried setting the page after calling draw the first time, just to see if it would work, like this:

table.page(3).draw('page');

But d.start is always 0.
Could you guide me on what the problem might be?

Replies

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @Dzyann ,

    Take a look at this example here, this is using displayStart to set the initial page. This is all you need to do - the server script should then send the correct data.

    Hope that helps,

    Cheers,

    colin

  • DzyannDzyann Posts: 12Questions: 3Answers: 0

    I tried setting the displayStart also but it didn't work. It kept sending 0.

  • DzyannDzyann Posts: 12Questions: 3Answers: 0
    edited May 2018

    I tried redrawing the table in the initComplete and it didn't work. At first I thought it worked, but it didnt, it just moves to the next page but it doesnt actually load the correct data. It only shows like is in the third page but with the data of the first page.

    "fnInitComplete": function (oSettings, json) {
                if (myJqueryTable !== undefined)
                    myJqueryTable.page(3).draw('page');
            },
    
  • kthorngrenkthorngren Posts: 21,117Questions: 26Answers: 4,916
    edited May 2018

    I suspect the page() is a client side only API based on this comment in the docs:

    Note that if you attempt to show a page which does not exist using the set format of this method, DataTables will not throw an error, but rather reset the paging to the first page.

    I put together this simple example which exhibits the same behavior you are seeing with Datatables requesting page 0.
    http://live.datatables.net/molezica/1/edit

    Here is an example using displayStart that works correctly:
    http://live.datatables.net/fewaqidu/1/edit

    Did you still have the table.page(3).draw('page'); when trying this?

    Kevin

  • DzyannDzyann Posts: 12Questions: 3Answers: 0

    Hi @kthorngren I didn't have the table.page(3).draw('page'); when I tried using the displayStart option, however, just in case, I tried again without setting the page, and it still doesn't work. Maybe my mistake is that I should be setting the page in addition to the displayStart?

    It certainly would seem it has issues with the server side feature, but as far as I can tell the pagination buttons work calling the same API, so there has to be a way to make it work. Also, I added a button that set the table to the page 3 and it worked, which furthers confirm the issue is at load time.

    When using Server Side, it should be up to the server to decide if the page number are valid, the datatable.net should request the correct page, but it is always starting at 0.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @Dzyann ,

    My example above does show that the client requests the 'displayStart` as expected, so there must be something in your configuration that's causing the issue.

    Have you debugged the Ajax request being sent, and the response being received? This may give clues - I suspect the starting correct value is being request but the server script isn't honouring it.

    If you could give a link to the page, or produce a test case demonstrating this problem, that would greatly help.

    Cheers,

    Colin

  • DzyannDzyann Posts: 12Questions: 3Answers: 0

    I will follow this up this weekend, please don't close the questions. I am trying to create a example outside of my application.

This discussion has been closed.