paging not working, pageLength always equals lengthMenu selected value

paging not working, pageLength always equals lengthMenu selected value

enzoNotFerrarienzoNotFerrari Posts: 4Questions: 1Answers: 0
edited July 2016 in Free community support

datatables 1.10.11

The following retrieves the selected length number of records from ajax. I was expecting to see x number of pages of 50 rows for lengths greater than 50, instead I get 1 table with length number of rows to scroll through. I have pageLength set to 50, but default of 10 is ignored as well. Is this the correct behavior, or am I missing something?

$('#pastes_table').dataTable({
        "searching": false,
        "ordering": false,
        "lengthChange": true,
        "processing": true,
        "serverSide": true,
        "lengthMenu": [[25, 50, 100, 500, 1000],[25, 50, 100, 500, "Max"]],
        "pageLength": 50,
        "ajax": "/pastes/" + search,
        "language": {
            "infoEmpty": "Please add Keyword first!",
        },

Thanks.

Answers

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin

    Sounds like the server-side processing script might not be handling the request and returning 50 rows correctly. However, we'd need a link to a page showing the issue, per the forum rules, in order to be able to check and offer any help.

    Allan

  • enzoNotFerrarienzoNotFerrari Posts: 4Questions: 1Answers: 0

    I've tried to get a sample running on jsfiddle, but haven't had much luck thus far.

    I have verified that server is returning the expected number of rows, which are then displayed in their entirety with a scrollable window, instead of paging to the defined pageLength.

    Ex. Select 500 rows to retrieve. Server returns 500 rows(verified), then client displays all 500. I was under the impression that since pageLength = 50, I would get 10 pages of 50 rows.

    I'll continue to try to get a test page to share.

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin

    ve. Server returns 500 rows(verified), then client displays all 500. I was under the impression that since pageLength = 50, I would get 10 pages of 50 rows.

    You should. It sounds like the server-side implementation isn't correctly detecting the fact that the page length is 50 and therefore limiting its results to only 50.

    Allan

  • enzoNotFerrarienzoNotFerrari Posts: 4Questions: 1Answers: 0
    @app.route('/pastes/<string:search>', methods=['GET', 'POST'])
    def pastes(search):
        start_from = int(request.args.get('start'))
        list_size = int(request.args.get('length'))
        page_no = start_from / list_size
        paste_recs = Utils.getPastes(foo, page_no, list_size)
        paste_data = {}
    
        if 'success' in paste_recs:
            paste_data['draw'] = request.args.get('draw')
            paste_data['recordsTotal'] = len(paste_recs['data'])
            paste_data['recordsFiltered'] = len(paste_recs['data'])
            i = 1
            p_data_full = []
    
            for paste in paste_recs['data']:
                
                # Do stuff
    
            paste_data['data'] = p_data_full
        else:
            paste_data['draw'] = request.args.get('draw')
            paste_data['recordsTotal'] = 0
            paste_data['recordsFiltered'] = 0
            paste_data['data'] = {}
    
        result = json.JSONEncoder().encode(paste_data)
        return result
    

    start is always being passed as 0
    length is selected length
    so always requesting/returning length number of records

    Sorry for my nubeness, but I'm clearly missing something here.
    How do I utilize pageLength server-side? The start value has to somehow change.

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin

    I'm afraid I don't even recognise what language that is so I can't really help. All I can say is that if DataTables requests 50 rows, it should get back 50 rows maximum. If it is getting more than that, there is an error in the server side script.

    Allan

  • enzoNotFerrarienzoNotFerrari Posts: 4Questions: 1Answers: 0

    Language is python using flask.

    DataTables is getting the number of rows it requests, but it's not paging the results. It's just showing all of the rows.

    I have pageLength set to 50. If I request 100 rows, 100 rows are retrieved and sent back. It then displays all 100. Paging values are grayed out, and it says "Displaying 1 to 100 of 100." I would instead expect to see "Displaying 1 to 50 of 100" with the page 1 and 2 being clickable to each page.

    The ajax object returned has 100 rows in it. All 100 get displayed at once regardless of pageLength setting.

    In the live example the AJAX has 57 records, but only "show" length number are displayed. That's the behavior I'm looking for, but can't seem to achieve. If my AJAX has 100 records, how do I only display 50 or whatever number at a time?

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin

    It sounds like you need to disable the serverSide option. If you have server side processing enabled, only the number of rows requests should be returned - see this example - 10 rows are loaded for every draw.

    If you are going to send the full data set to DataTables, then don't do server-side processing - let the client-side do it.

    Allan

This discussion has been closed.