update rows with array of data using draw()

update rows with array of data using draw()

Hitesh279Hitesh279 Posts: 5Questions: 3Answers: 0

Hi can you please help me on iterating an array to update row using draw().

modalInstance.result.then(function (editRecapGYORVal) {
var rowsData = vm.dataTableInstance.rows({selected:true}).data();
for(var i=0;i<rowsData.length;i++){
rowsData[i].gyor = editRecapGYORVal;
dtRow.data(rowsData[i]).draw();
}
//dtRow.data(rowsData).draw();
//console.log(rowData);
}

I am using above code but it is updating rows with one object data.
for an example my rowsData object holding 2 objects for but when I am iterating the array it always draw 2nd object datas.

This question has an accepted answers - jump to answer

Answers

  • pingcrosbypingcrosby Posts: 29Questions: 4Answers: 1
    Answer ✓

    HI am struggling to read your markup can you use the markdown codes for your javascript source eg your source code

    see here https://datatables.net/tn/8

    Also not sure you want to call draw after each row update - think your better of updating each row then calling draw to redraw the table once when complete

    /// in pseudo code
    for(... all rows in table)
    {
        rows.data(newData);
    }
    table.Draw(); // called once at end of update
    
  • Hitesh279Hitesh279 Posts: 5Questions: 3Answers: 0
    edited February 2017

    The below code is for modal Instance .when you open this pop up using modal instance then save pop up whatever value we are passing from popup must be updating in specific rows.So in below code rowsData[i] is the array of selected rows and I am setting the value inside it and then I called draw().

    modalInstance.result.then(function (editRecapGYORVal) {
    var rowsData = vm.dataTableInstance.rows({selected:true}).data();
    for(var i=0;i<rowsData.length;i++){
    rowsData[i].gyor = editRecapGYORVal;
    dtRow.data(rowsData[i]).draw();
    }
    }
    
This discussion has been closed.