Pagination kinda sorta works but total recordcount is not being received

Pagination kinda sorta works but total recordcount is not being received

funneldrivefunneldrive Posts: 9Questions: 0Answers: 0

I have been doing this all day long. I'm using coldfusion/sql server/bootstrap4/jquery/datatables. I set up everything for server side processing. It loads my data I see the records. But the total records is never returned. I have check the ajax response 100 times. This is my response.. I abbreviated the data records but it returns 10 of them

{
    "RecordsFiltered": 63607,
    "RecordsTotal": 63607,
    "draw": 1,
    "data": [
        {
            "CATEGORY": "Amenities",
            "PRETTY_QUESTION": "Is there air conditioning and a hairdryer in the room?",
            "NEW_ANSWER": "Yes, the rooms have air conditioning and a hairdryer.",
            "UHID": 1234,
            "ID": 999,
            "QUESTION": "Is there air on and hairdryer in the room"
        }
    ]
}

Even looked at my javscript console the values for the record counts are coming back. I get my data when I click the page number in the pagination. But table says: Showing 0 to 0 of 0 entries (filtered from NaN total entries)
even though I'm seeing the data. I just don't know where else go here been at this for hours here is my definition table

<script>
$(document).ready(function() {
    var table = $('#aiDataTable').DataTable({
        ajax: {
            url: 'mgmt-data.cfm',
            type: 'post',
            dataSrc: 'data'
        },
        serverSide: true,
        columnDefs: [
            { targets: [0], data: 'ID', orderable: false },
            { targets: 1, data: 'UHID' },
            { targets: 2, data: 'CATEGORY' },
            { targets: 3, data: 'QUESTION' },
            { targets: 4, data: 'PRETTY_QUESTION' },
            { targets: 5, data: 'NEW_ANSWER' },
        ],
        order: []
    });
});
</script>

I even looked at api.page.info() which show me this in console:

{page: 0, pages: NaN, start: 0, end: NaN, length: 25, …}

It like almost works but not getting the record count is screwing it up so the Next button doesn't work right. Oddly enough it can pull the data on all the pages correctly.

Replies

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Take a look at the expected return data for server side processing. Datatables is expecting recordsTotal and recordsFiltered with lower case r. You have RecordsTotal and RecordsFiltered. Correct the case of the leading r and it should work.

    Kevin

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Looks like you can just use the columns option instead of columnDefs, like this:

            columns: [
                { data: 'ID', orderable: false },
                { data: 'UHID' },
                { data: 'CATEGORY' },
                { data: 'QUESTION' },
                { data: 'PRETTY_QUESTION' },
                { data: 'NEW_ANSWER' },
            ],
    

    Kevin

  • funneldrivefunneldrive Posts: 9Questions: 0Answers: 0

    OMG! Thank you I stared at this for hours. Saved my bacon

Sign In or Register to comment.