Page length - lengthMenu not implemented in Serverside

Page length - lengthMenu not implemented in Serverside

robsimpsonrobsimpson Posts: 36Questions: 8Answers: 1

Am I correct in concluding that lengthMenu is not available in server side?

I'd like the user to be able to select how many records they have on the page, primarily so they can view 100's of records occasionally (mainly for exporting) while generally viewing an aesthetic few. More specifically, my user moaned that she now couldn't choose for herself, as she had been able to before we went to server side.

I guess I could implement my own menu and .hide() all records over a threshold, although that might be a performance hit bringing back all the (say, 500) records every time.

Thanks,

Rob

Replies

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406
    edited June 2022

    Am I correct in concluding that lengthMenu is not available in server side?

    No, you aren't. Why do you think it isn't available? All you need to do is turn paging on. Then the length menu appears automatically.

    I have just tested it: The default length menu appears when paging is turned on. But you can't change the defaults using "pageLength" and "lengthMenu". Server side ignores those custom settings. Amazing. My users were ok with the default settings for paging. So I've never had an issue with that.

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    Maybe this FAQ explains the issue?

    Kevin

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406

    While I couldn't change "pageLength" and "lengthMenu" using the intialization options I was able to change page length using an event handler.

    This worked with my server side table:

    forexTable
        .on ('init', function () {
            forexTable.page.len(5);
    ...
    
  • robsimpsonrobsimpson Posts: 36Questions: 8Answers: 1

    No, you aren't. Why do you think it isn't available?

    Ahh, perhaps it is not available in Editor then. There is not a single example of lengthMenu in the Editor examples. I switched to ss & using Editor about the same time.

    Certainly I can set pageLength, but lengthMenu instead does nothing.

    Is it available in Editor?

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    Did you read the FAQ I linked to. I think it will answer your question.

    Kevin

  • robsimpsonrobsimpson Posts: 36Questions: 8Answers: 1

    Kevin,

    This one?

    Q. How can I show the page length select when using Buttons?
    A. This question arises when you use the dom option to insert the Buttons into the >page, but the l character in the dom string is removed (which it is in many Buttons >examples). You could use the pageLength button to insert a page length button list, >or add the l option back into the dom string.

    I have:

    dom: 'PQBlfritp',
    

    The lower-case L is there.

    Thanks,

    Rob

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    Your code snippet works in this test case:
    http://live.datatables.net/pidolijo/1/edit

    Maybe you have lengthMenu set to false in your Datatables init code or a jQuery or Javascript statement removing the element from the page. Server Side Processing and the Editor support the use of the Length Menu. Please update the test case to show the issue or provide a link to your page so we can help debug.

    Kevin

  • robsimpsonrobsimpson Posts: 36Questions: 8Answers: 1

    Kevin,

    that example isn't serverside, I think.

    Is it okay to PM you a link?

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    Ok, since you still doubt the length menu works with server side processing I created a new test case with SSP, Editor, Search Panes, Search Builder, Excel and PDF buttons.
    http://live.datatables.net/guwafemu/271/edit

    Changing the page length works. Note that SP and SB don't work as the server script doesn't support the protocol needed for them to work.

    You can PM me the link but I don't work for Datatables. If you prefer you can PM the link to Allan.

    Kevin

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin

    Yup - drop me the PM please. Kevin is an amazing person who helps out in the forum, but debugging stuff should come to me so we don't abuse his goodwill :)

    Allan

  • robsimpsonrobsimpson Posts: 36Questions: 8Answers: 1

    Kevin, wow, than - you've provided a very clear illustration. I'll have another look at my code and if I still can't solve it I will PM to Allan.

    Thanks for all your time and effort, much appreciated.

    Rob

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406

    Sorry, you guys lost me :smiley:
    But, never mind...

    If I look at your initial question, Rob, I think my suggestion works:

    I'd like the user to be able to select how many records they have on the page, primarily so they can view 100's of records occasionally (mainly for exporting) while generally viewing an aesthetic few. More specifically, my user moaned that she now couldn't choose for herself, as she had been able to before we went to server side.

    Using serverSide this would be the key table settings:

    var table = $('#yourTable').DataTable( {
        dom: "Bfrltip",
        serverSide: true,
        paging: true,
    ....
    

    Combined with this event handler you should get what you need:

    table
        .on ('init', function () {
            table.page.len(5);
    ...
    

    You should have the standard page length menu and an initial page length of 5 instead of the default 20. Afterwards the user can choose whatever she likes.

    This is what you should see:

    Isn't that what you want? Am I missing something here?

  • robsimpsonrobsimpson Posts: 36Questions: 8Answers: 1

    Kevin, I found the problem going through my code line by line. I misunderstood the lengthChange param and had it set to false! Agggh! But sorted now. I'm very grateful for your time.

    rf1234, yes I can do that now - processing is quick with smaller numbers, but if they need to export a load of data they can choose to do so.

    Allan, sorry to waste your time.

    Thanks all, great support.

    Rob

  • robsimpsonrobsimpson Posts: 36Questions: 8Answers: 1

    Not sure how to mark this thread answered...

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406

    I think you can accept one or several answers and then you're done :smile:

    Thanks all, great support.

    You are welcome! And I agree with you. That's why I am trying to help out every once in a while: Trying to give back some of the support I've been receiving over the years.

Sign In or Register to comment.