Problem facing in using of fnAddData for appending rows in the grid . Rows are not being displayed.

Problem facing in using of fnAddData for appending rows in the grid . Rows are not being displayed.

AshishGAshishG Posts: 5Questions: 1Answers: 0

Hello Allan,

I am new to Datatables and still learning it. I am stuck at one place. I am using Datatable version 1.9 (So rows.add() cannot be used, i guess).

.success(function(data){
var rows = data.data;
for(var i =0; i<rows.length;i++){
var tempArray = [];
$.each(rows[i], function(k,v){
tempArray.push(v);
});
$('.grid').dataTable().fnAddData(tempArray,false);
}
console.log("success");
});

Answers

  • kevin1293909kevin1293909 Posts: 17Questions: 3Answers: 0
    edited November 2014

    Since you are declaring the second parameter of false you need to call fnDraw after so something like:

     $('.grid').dataTable().fnAddData(tempArray,false);
     $('.grid').dataTable().fnDraw();
    

    or if you don't need to declare false, you could simply remove false and it should work!

    Also make sure to call fnDraw outside of the for loop so that all of the rows are rendered first

  • AshishGAshishG Posts: 5Questions: 1Answers: 0

    @kevin But that's my concern, I don't want to redraw the table.

  • kevin1293909kevin1293909 Posts: 17Questions: 3Answers: 0
    edited November 2014

    Is there a reason you cant use 1.10? If you are new why not just start with the newest release?

    Also, I am not sure you can update your display without redrawing the table

  • AshishGAshishG Posts: 5Questions: 1Answers: 0

    Well, the existing project is on the top of 1.9 so using the legacy datatables only I have to solve this problem.

This discussion has been closed.