Dynamically get current column on a table

We are setting background color on our table dynamically based on a few information: if the cells is editable and if it has been edited on a previous session by the user.

The issue is that when we send the information to the function that returns the background color we need to get this information from the column, and since our table has more than 200 columns, it would be better to do this in a dynamic way (for maintanence purposes also).

The callback for the function is {{ coloringFn("columnId", "rowId", "currentValue", "previousValue") }} . We are unable to get the columnId dynamically.

Hi @fmaltafleury-techinsights , have you tried using item? You could do something like {{ coloringFn(item, "rowId", "currentValue") }}. I'm not sure what you want to do with row ID and currentValue but item should return the column ID for each row!

Unfortunately the β€œitem” is returning just the value, not the column ID

Ah yeah I misunderstood you there. To get the column ids programmatically this should work: Object.keys(self.data[0])[i] instead of item.

If I'm not mistaken, "i" return the row index number, not the column index number.

1 Like

Still not able to do it that way on a dynamic column, maybe it is not possible at this point?

Yeah, my mistake again. You can reference item for the value in that column, i for the row number, and self for the whole table, but there is no built-in reference to the specific column you're on.

Unfortunately you'll either have to hardcode it or transform your data to have key-value pairs, in which you could access the column name through the item keyword.

1 Like