Closed travis-leith closed 1 year ago
Seems to be something to do with DateTime
and converting to string.
If I remove all valueFormatter
s for DateTime columns, everything works.
If I try to convert to string in the valueGetter
instead of the valueFormatter
, I get a different error:
Uncaught TypeError: Cannot read properties of undefined (reading 'offset')
at toString (Date.js?22b6:133:1)
at GridHelpers_dateTimeString (DeskOrders.fs?a349:86:20)
at eval (DeskOrders.fs?a349:186:47)
at ExpressionService.evaluate (ag-grid-community.cjs.js?982d:32392:1)
at ValueService.executeValueGetter (ag-grid-community.cjs.js?982d:28459:1)
at ValueService.getValue (ag-grid-community.cjs.js?982d:28288:1)
at CellComp.getValue (ag-grid-community.cjs.js?982d:21414:1)
at CellComp.getValueAndFormat (ag-grid-community.cjs.js?982d:21397:1)
at new CellComp (ag-grid-community.cjs.js?982d:20699:1)
at RowComp.newCellComp (ag-grid-community.cjs.js?982d:42687:1)
Incidentally, if I navigate to a 3rd empty tab with no grid render at all, then back to first tab, everything works fine. So I don't know if this bug is in this repo, or in the underlying agGrid repo.
if I navigate to a 3rd empty tab with no grid render at all, then back to first tab
This makes me wonder if setting a different AgGrid.key
for the two grids would fix the problem. I believe this sets the React key which only needs to be unique amongst its siblings (and in this case different in the two grids as well).
This worked! Thanks. Although I don't understand why and searching this is difficult because results for "aggrid key" all refer to a license key.
Try this instead: https://reactjs.org/docs/lists-and-keys.html
My understanding is that every React element has a key and if not specified, they are generated automatically. In most cases that works fine. The whole "path" of keys (from the root element through the descendants down to the element), uniquely determines the element on the page.
Sometimes, if a component appears in the same position as one before it, it will have a the same auto-generated key. And if it's a stateful component like ag-grid, then the wrong state will be carried over to the new element and things will go wrong.
It's best to give every ag-grid in your app a unique key. And it's also best for performance to give list elements a key based that uniquely identifies the list item, if possible.
Full error:
I don't think I am doing anything special here. I have 2 grids, on 2 different tabs. I click a button which is located in the first grid, which opens the other tab and populates content on the other grid. Switching back to the first tab raises this error.