Table not updated when moving backwards - server-side data processing

Table not updated when moving backwards - server-side data processing

taipantaipan Posts: 2Questions: 1Answers: 0
edited August 2023 in Free community support

Hello,

I would like to ask what is the proper way to deal with the following issue. I am using DataTables version 1.13.6 from CDN. I am initializing the table and serverSide is set to TRUE. I have read the documentation about that type of processing data and also about the draw parameter. When i am moving from lower to higher page, for example 1 > 2 >3 >5 there are no problem, data is returned and drawn. When I am moving from lower to higher and then back to lower page, at that point data is not drawn even though is returned. For example: 1 > 2 > 4 > 3(table stuck on processing and data is not drawn). I have read that draw parameter is consecutive and also found the IF condition that is triggered in that scenario.

MY CODE:

table = $('#tableID').DataTable({
    dom: 'rtip',
    ajax: {
        url: 'end_point',
        cache: false,
        type: 'POST',
        data: function (d) {
            let tableInfo = 1;
            if ($.fn.DataTable.isDataTable('#tableID')) {
                tableInfo = $('#tableID').DataTable().page.info();
            }
            console.log('Table info: ', tableInfo);

            return JSON.stringify(tableInfo);

        },
        dataSrc: function (receivedData) {
            console.log("Draw variable: ", receivedData['draw']);
            console.log('The data has arrived'); // Here you can know that the data has been received
            console.log(JSON.stringify(receivedData['data'])); // Here you can know that the data has been received
* 
            return receivedData['data'];

        },
        error: function (xhr, error, thrown) {
            console.log('here you can track the error');
        }
    },
    processing: true,
    serverSide: true,
    bFilter: false,
    bInfo: false,
    responsive: true,
    columns: [
        {data: 0},
        {data: 1},
        {data: 2}
    ],
});

Code from datatables.min.js

if (r !== H) {
            if (+r < t.iDraw) return; - THIS ONE
            t.iDraw = +r
        }

What is the proper way to make my table possible to move backwards also? Is there any way to manilupate the t.iDraw parameter?

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,236Questions: 1Answers: 10,418 Site admin

    When I am moving from lower to higher and then back to lower page, at that point data is not drawn even though is returned

    That is correct and expected. The draw parameter is used to ensure only the latest request is drawn, since the request is asynchronous. It might well be what you are encountering, but consider a search request for a large amount of data, immediately followed by one for a narrow set. The narrow set might return first, which means the large request should never be drawn.

    The draw parameter is sequential and the server should only return the value it was submitted (parsed as an integer for security).

    1 > 2 > 4 > 3

    In such a case the data for draw 4 should be shown on the page. 3 should be "thrown away". It should not get stuck on "Processing...". If it is, can you give me a link to a page showing that issue so I can look into it please?

    Allan

  • taipantaipan Posts: 2Questions: 1Answers: 0

    Hello,

    Thank you for your comment.

    Unfortunately, the web site is on corporate machine. I try to build example and host somewhere else. I will right, when I am ready.

    taipan

  • allanallan Posts: 63,236Questions: 1Answers: 10,418 Site admin

    That would be great, thanks!

    Allan

Sign In or Register to comment.