Server side pagination problem

Server side pagination problem

CamelCamel Posts: 5Questions: 1Answers: 0

INTRO
I ran into strange problem: my datatable is showing "Showing 11 to 10 of 10 entries " which is obviously nonsense. I think this could be kind of bug.

I am using PHP server side processing, stateSave: true, resetDisplay: false, processing: true, serverSide: true and some others which I believe are not important.

Let's assume I am showing just some active data, 11 records in total, page length 10 rows => 2 pages withou filter.
When I go to some editation form directly from datatable **second ** page and deactive one record and go back, I am getting message you can see above. AJAX parameters are start:10 and length:10.

Obviously, datatable tries to load / thinks I am still on second page which "doesn't exist" anymore.

The question is how can I handle this. I can handle it on server side like:


if (filteredCount === offset) {
offset = 0;
}


but I am still getting bad message. Thx for your thoughts!

This question has accepted answers - jump to:

Answers

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    What do you mean by "deactive one record"?

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736
    Answer ✓

    I might not understand your issue correctly but it sounds like the same behavior as discussed in this thread:
    https://datatables.net/forums/discussion/comment/117240/#Comment_117240

    Kevin

  • CamelCamel Posts: 5Questions: 1Answers: 0

    I am showing just some active data, it means that I am filtering some records from table which have column active = 1. By deactivate I mean setting this column active to 0. Basically it's the same as if I would delete some record.

    Thx for link @kthorngren , this is exactly my case
    https://datatables.net/forums/discussion/comment/117240/#Comment_117240

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Bugs are like busses - they all come along at the same time!

    Allan

  • CamelCamel Posts: 5Questions: 1Answers: 0

    OK, the problem was fixed in 1.10.16 but now stateSave: true stopped working.

    When I am on eg. second page and I refresh it, I am back on first page. Sometimes it even serves me second page, but in pagination first page is selected.
    I have tried it with previous version from my GIT and it worked.

    Can someone confirm it? Thx

  • btreebtree Posts: 99Questions: 14Answers: 11
    edited September 2017

    stateSave: true is working.

    But yes seems like the start param is saved correctly but on refresh ignored.

    Actually I like this behaviour, think I will remove the paging from being saved for my tables. :wink:

    Cheers
    Hannes

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Seems to work as expected for me here. @Camel - Can you link to a page showing the issue please.

    Allan

  • btreebtree Posts: 99Questions: 14Answers: 11

    I'm not Camel but I got a "not" working Test case.

    https://www.btree.at/beta/table/hive/
    Login: demo_en@btree.at
    PW: demo_en

    Cheers
    Hannes

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Thanks! However, I get "Wrong email or password!" when using those credentials.

    Allan

  • btreebtree Posts: 99Questions: 14Answers: 11

    Hi Allan,

    off topic sorry: You may found a bug in my beta page. Can you tell me which browser and version you use, because it works fine for me.

    Thanks
    Hannes

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Hi Hannes,

    Just tried it again and same result. Its Chrome 60 / Linux (Fedora 26).

    Allan

  • CamelCamel Posts: 5Questions: 1Answers: 0
    edited September 2017

    I have just done some research and I found out, that problem is, when
    responsive is set to true (responsive: true). I am using serverSide and AJAX is called twice. When I disable responsive extension, it's normally called just once.

    I also commented all other javascript code to be sure that there is no problem somewhere else in my code.

    I checked responsive extension with AJAX call here on this site, but it's working (strange).

    Windows 10, Chrome 61.0.3163.91, Datatables 1.10.16, Responsive-2.2.0, datatable settings:

    ajax: {
    url: ajaxUrl,
    type: "POST",
    data: additionalData
    },
    resetDisplay: false,
    processing: true,
    serverSide: true,
    responsive: true,
    stateSave: true,
    dom: 'Blfrtip',
    buttons: [{ .... }],
    columns: columns,
    language: { ... },

  • btreebtree Posts: 99Questions: 14Answers: 11

    @allan thank you and sorry cant replicate the problem. Login works fine on all major browser, but i don't have Fedora to test it.
    I create a new user but dont think this is the problem.
    Login: datatables@btree.at / PW: datatables

    @Camel
    Good spot did miss this. Yes the ajax is called two times with reponsive true, but only on first init.

    I created a debug file, maybe this helps:
    https://debug.datatables.net/ijavum

    Cheers
    Hannes

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    That worked this time - thanks.

    You have:

    "stateDuration": 0,

    So yup - the state would never be reloaded since it expires immediately.

    That it didn't before was a bug in older versions.

    Allan

  • btreebtree Posts: 99Questions: 14Answers: 11
    edited September 2017

    @allan do i miss something, I want no timeLimit at all.
    https://datatables.net/reference/option/stateDuration

    The value 0 is a special value as it indicates that the state can be stored and retrieved indefinitely with no time limit.

    Things like row sorting or page length are saved correctly on my page, so there must be a different thing?

    PS.: Second do you also see the double ajax call on init?

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Urgh - I'm forgetting how my own code works - sorry. I'll need to dig into this and try to reproduce it.

    Allan

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Answer ✓

    I think we've got it sorted in this thread now. Thanks for flagging this up!

    Allan

  • CamelCamel Posts: 5Questions: 1Answers: 0

    Thx for quick fix & all answers!

  • ashis82ashis82 Posts: 6Questions: 0Answers: 0

    Pagination issue still reproducible in latest version 1.10.20. This issue is same as this thread - https://datatables.net/forums/discussion/comment/117240/#Comment_117240

    My settings are:

    processing: true,
    paging: true,
    pageLength: 50,
    ordering: true,
    info: true,
    serverSide: true,
    stateSave: true
    

    NOTE: Even after deleting the record from table the local storage values remains unchangeable.

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    @ashis82 Allan posted steps to reproduce the problem in that thread you posted, but that's no longer occurring, so it would suggest either the problem is fixed, or it's changed shape.

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • ashis82ashis82 Posts: 6Questions: 0Answers: 0

    @colin Thanks for your quick reply.

    Please login to this account.
    https://demo.usesphere.com/admin/site/login
    User: test@usesphere.com
    Password: test1234

    Reproducible steps:
    1. Access people page from left menu (https://demo.usesphere.com/admin/leads/index)
    2. Move to page 4 of the listing.
    3. Select the check boxes and delete the record from the menu. Please make sure all the records from page 4 should be deleted.

    Note: You can add records to datatable using "Add people" link available on top of listing.

    Observation
    - After deletion It still stays on the same page i.e. 4th page which yields to "No matching records found" message.
    - As we use statesave=true, even after page refresh, it still shows the 4th page.

    Datatable Settings:

    processing: true,
    paging: true,
    pageLength: 50,
    ordering: true,
    info: true,
    serverSide: true,
    stateSave: true
    
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Thank you for letting me know about this. It looks like an issue when using serverSide processing and state saving. I don't have an immediate fix, but have logged this in our issue tracker for the next release to address it.

    Allan

  • ashis82ashis82 Posts: 6Questions: 0Answers: 0

    @allan Thanks for your response. I will definitely wait for that fix.
    Is there any link where I can track this issue. I have also subscribed to the github repo (https://github.com/DataTables/DataTables).

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Is there any link where I can track this issue.

    No, sorry, this is an internal system. The issue (DD-1342 for my reference) has this thread recorded against it, so we'll update here when it's progressed.

    Colin

  • pawellabajpawellabaj Posts: 1Questions: 0Answers: 0

    There is no update in the thread. Does it mean the bug still exists?

    BTW, I've found this thread because of https://wordpress.org/support/topic/pagination-from-saved-state-is-reset-to-0/

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Yep, sorry, the bug is still in the same state. I'll see if it can be expedited.

    Colin

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    What we need to add is a mechanism for the server-side script to say that there is no data where data was requested (in terms of paging), but there is (or might be) data else where. In a similar vain, we've got a request to add the ability to indicate that there is more data available, but not putting a specific number on it. We'll probably be looking at these as part of our work on DataTables 2.

    Allan

Sign In or Register to comment.