Page 1 of 1

Access all record columns (even those that have zero or undefined value)

Posted: Mon Oct 14, 2019 5:32 am
by bensullivan
Hi

How do I iterate through a records column (type = percent) values including the ones that are 0%? record.data only seems to have the columns that have been set and Object.keys(record) does not display the missing columns either.

Thanks

Ben

Re: Access all record columns (even those that have zero or undefined value)

Posted: Mon Oct 14, 2019 9:11 am
by Maxim Gorkovsky
Hello.
I'm afraid it is not clear what are you trying to iterate, row values visible in the grid or values of the column of a certain type.

It might be difficult to iterate row cells: column decides what to render in the cell and that value is written to the DOM element. So, in case there is a renderer, you will have to either iterate over visible columns, triggering rendering, or query DOM for cell content. But for a simple case when you just put record value to the cell, you can do it using visibleColumns property:
grid.columns.visibleColumns.forEach(column => {
  let value = record[column.field]
})
Iterating column values is similar, using forEach:
grid.store.forEach(record => {
  let value = record[column.field]
})

Re: Access all record columns (even those that have zero or undefined value)

Posted: Mon Oct 14, 2019 10:43 pm
by bensullivan
Thanks Maxim - I will give visibleColumns a try..

Thanks

Ben