total count not being displayed correctly while waiting for response when using iDeferLoading

total count not being displayed correctly while waiting for response when using iDeferLoading

anthonybellanthonybell Posts: 4Questions: 1Answers: 0
edited May 2014 in DataTables

Hi, I'm trying to have the first page already populated while the ajax call is getting the rest of the table (for better "perceptual performance"). I populate the html with the first page of records on the server, set iDeferLoading: <number of records>, and set bServerSide: false. The problem is that the 2-3 seconds it takes for the ajax call to return the datatable shows "Showing 1 to 10 of 10 entries" and the pagination controls indicate there is only one page. Below is my code. When the ajax call returns it shows the correct number and the pagination controls show that there are many pages. When I turn on bServerSide it works correctly (but I want to keep processing on the client side). Is this a bug or is there so other way to do this?

 $dataTable = $("#dataTable").dataTable({
            bPaginate: true,
            bProcessing: false,
            bServerSide: false,
            bSortClasses: false,
            bDeferRender: true,
            iDeferLoading: $num_records,
            sAjaxSource: $url,
            fnServerData: function (sSource, aoData, fnCallback) {
                $.ajax({
                    dataType: "json",
                    type: "GET",
                    url: sSource,
                    data: {},
                    success: function (result) {
                        if (result.Success) {
                //we already have the first 10 so slice them out!
                            fnCallback(result.Data.slice(10));
                        } else {
                            showMessage(result.Message);
                        }

                    }
                });
            },
          
        });

Thanks,

Anthony Bell

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi Anthony,

    Are you able to link to a test case showing the issue? There is my example of that option in action and it seems to work okay: http://datatables.net/examples/server_side/defer_loading.html , so I think I'd need to be able to see a test case of it not working to understand what is going wrong.

    Regards,
    Allan

  • anthonybellanthonybell Posts: 4Questions: 1Answers: 0
    edited May 2014

    Here is a jsFiddle: http://jsfiddle.net/abell25/3ne2H/3/
    I have set iDeferLoading: 6, but the table shows "Showing 1 to 2 of 2 entries".
    It should say "Showing 1 to 2 of 6 entries" (and it does when using server-side loading).

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Why

    "aaData": the_data,

    if the_data is not what you want?

  • anthonybellanthonybell Posts: 4Questions: 1Answers: 0
    edited May 2014

    the_data is just the first page in this very simple example. It is pre-loaded to increase the perceived loading time. A real example would preload 10 records and use ajax to grab 1000+ records.

This discussion has been closed.