ajax call is n't trigged after second fetch

ajax call is n't trigged after second fetch

chamartschamarts Posts: 2Questions: 1Answers: 0
edited October 2018 in Free community support

HI All,

I am using datatable with the following configuration with serverSide processing set to true but somehow the table doesn't fetch data after second ajax call.

I am displaying 100 records for each call and I have 15000 records in database. But somehow after second page, it doesn't trigger any ajax calls. Please let me know if I am missing anything. Appreciate any help.

$('.status').DataTable({
        serverSide: true,
        cache: true,
        ordering: true,
        lengthChange: false,
        order: [1,"desc"],
        responsive: false,
        searching: false,
        scroller : {
        loadingIndicator: true,
    },
    deferRender:true,
    language: {
         emptyTable:  "No records to display",
         infoEmpty: "No records available"
    },  
    scrollY : 480,
    scrollCollapse:true,
    drawCallback: function(settings) {
    },
     ajax: function ( data, callback, settings ) {
            var renderTable = function() {
                console.log("Total Records::" + ajaxResponse.recordsTotal);
                console.log("NumberOfRecordsFetched::" + ajaxResponse.data.length);
                console.log("Draw::" + data.draw);
                this.deferLoading = ajaxResponse.recordsTotal;
                var out = [];
                for ( var i=data.start, j=0,ien=data.start+ajaxResponse.data.length; i< ien; i++,j++) {
                    out.push(ajaxResponse.data[j]);
                }
                setTimeout( function () {
                    callback( {
                        draw: data.draw,
                        data: out,
                        recordsTotal: ajaxResponse.recordsTotal,
                        recordsFiltered: ajaxResponse.recordsTotal
                    } );
                }, 50 );
            };
            callAjax(renderTable);
        }
});

thx
~sri

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @chamarts ,

    I'm not sure what your code is doing there - I'd expect there to be a URL that you call, see the examples here. The best bet is to look at those examples - they should help.

    Cheers,

    Colin

  • chamartschamarts Posts: 2Questions: 1Answers: 0

    HI @Colin ,

    thanks for quick reply. I am actually using the function for ajax instead of a plain url since I have pre-processing that needs to be done.

    thx
    srinivas

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited October 2018

    Looks like you based your code off this example:
    https://datatables.net/extensions/scroller/examples/initialisation/server-side_processing.html

    There are two main differences:
    1. Data source - ajaxResponse in your case
    2. You are calling the function callAjax()

    Since the example code seems to be working and yours is not I suspect the problem may be in the callAjax() function. This will be very difficult to help troubleshoot without actually seeing it run. Can you post a link to your page or a test case showing the issue?

    Are you getting any errors in your browser's console?

    Kevin

This discussion has been closed.