Datatable loops over data three times

Datatable loops over data three times

jrbulnesjrbulnes Posts: 5Questions: 0Answers: 0

My datatable was too slow. Inside a have a function to call for more data to do some checking. I've noticed it that the function was call three times for each row. I commented out the call to the function add an alert and noticed that any way the table goes over the data three times before it display it.

Replies

  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin
    edited February 2015

    What function? If you could post a link to a test case showing the issue as required in the forum rules that would be good.

    Thanks,
    Allan

  • jrbulnesjrbulnes Posts: 5Questions: 0Answers: 0
    edited February 2015

    It is a regular function to get more data. Like I said even if I commented out the data loops three times. Here is how I call my function. Since I am using server data I don't know how to give you a link to a test case, I just answerered a couple of questions from other people an neither of them had links. Thank you.

    { "mData": null,
        "render": function ( data, type, full) {
        getReservationAttendee(data.reservationattendeeid,data.reservationid,data.cntvid);
        if (typeof USCID !== 'undefined') {
            return USCID;
        }   
        else {
            return '-';
        }
     }
                    },
    

    Here is how I comment out the call to my function and display an alert:

    { "mData": null,
        "render": function ( data, type, full) {
        alert(counter);
        counter++;
                //getReservationAttendee(data.reservationattendeeid,data.reservationid,data.cntvid);
    
        if (typeof USCID !== 'undefined') {
            return USCID;
        }   
        else {
                return '-';
            }
         }
    },
    
  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin

    I see - it is the columns.render function that you are concerned about? I didn't know that you were using that option.

    Yes, it will be called multiple times - is it expected and the desired behaviour. Every time DataTables needs to get data for that cell it will call that function. This is how orthogonal data is handled in DataTables.

    If your getReservationAttendee function is slow, then it might be worth caching the results to speed things up.

    Allan

  • jrbulnesjrbulnes Posts: 5Questions: 0Answers: 0

    Thank you for the explanation Allan, now I understand why it loops three times when using columns.render. I will ask for a new stored procedure to the DBA to avoid using render.

This discussion has been closed.