setDataAtCell sets data for all cells if table data generated by function

Tags: #<Tag:0x00007efc64545c88> #<Tag:0x00007efc64545af8>

Here’s a JSfiddle of my issue, adapted from a very nice little demo from a previous question.

I want to be able to dynamically generate the array for the data field of my table, but when I do that, setDataAtCell() doesn’t work as I would expect. I try to use the contextMenu to set the data and the CSS class of a selected cell, and it sets the CSS class correctly, but sets the data for every cell in the column instead of just the selected cell. If I create the same array of arrays manually and pass it in the data field, then setDataAtCell() works as expected.

How can I dynamically generate the table data before instantiating the table without causing this issue?

Hi @riese.matt

Thank you for contacting us. I used a slightly different method to generate an empty array of data, and it seems to be working correctly:

https://jsfiddle.net/handsoncode/ry7xdm1w/

Would that method also work for you?

Amazing! Yes that works for me.

Can you explain why these two ways of building the array of arrays have such different behavior, and why setDataAtCell is affected, but not setCellMeta?

@riese.matt

It looks like the second argument of your function took the value generated by setDataAtCell and spread it throughout the array of rows in a currently selected column.

It’s also worth mentioning that setDataAtCell causes the table to re-render by itself so there’s no need to call render() method if setDataAtCell and setCellMeta are used in one function.

ok, thank you for your help!

You’re welcome :slight_smile: