Troubles Updating Rows Dynamically

Troubles Updating Rows Dynamically

Igorski88Igorski88 Posts: 25Questions: 8Answers: 0
edited December 2019 in Free community support

I am currently trying to Update Rows Dynamically.
**What I tried: **
This only updates One of the rows.

jQuery.each(newDATA, function () {
table.row().data(this).draw();
});

This updates only have the rows

jQuery.each(newDATA, function () {
table.row().data(this);
});
table.draw()

I also tried this but it only updates one row

jQuery.each(newDATA, function () {
table.row().data(this).invalidate();
});
table.draw()

Any Ideas

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    You're using row(), if you want to update more than one use rows(),

    Colin

  • Igorski88Igorski88 Posts: 25Questions: 8Answers: 0
    edited December 2019

    I tried that as well.
    table.rows().data(NewData).draw();
    No updates are occuring. I see that the columns are being rerendered by checking my chrome console and I can verify that the Json data returned is the correct data. Any other advice?

    I also tried the following with now success:

    table.rows().data(NewData);
    table
    .row()
    .invalidate()
    .draw();

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    edited December 2019 Answer ✓

    EDITIED

    According to the rows().data() docs you can only get the row data:

    This method cannot be used to modify data in the table, only to retrieve it. Use the row().data() method instead which can be used as a setter.

    My guess is you aren't passing into row() the row-selector of the row you want to update. If you don't use a selector then the first row will be the only row updated which may be why you aren't seeing the updated as expected. You can see this in this example:
    http://live.datatables.net/demurupu/1/edit

    Select a row (not Tiger Nixon) then click the Update with selector button. The selected ro will be updated. Now click the Update Update without selector button and Tiger will be updated.

    Kevin

  • Igorski88Igorski88 Posts: 25Questions: 8Answers: 0

    @kthorngren you were correct. I needed to pass a row-selector. When I tried it in the past it didn't work because I was missing the pound sign. The following code in my loop did the trick. This was due to the fact that I was using a custom rowid.
    table.row("#" + this.ID).data(this)
    Also, if rows() is only a getter and not a setter I'm wondering why colin recommended it. He must know something we don't. Maybe the documentation is wrong?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Ha, no, I definitely don't know something Kevin doesn't :) It was early in the morning, and the coffee hadn't kicked in. Apologies for the confusion.

    Colin

This discussion has been closed.