[DataGridPro] When using 'pinnedRows', 'getRowClassName' causes error if 'rows' prop is empty array #5845
Closed
2 tasks done
Labels
bug 🐛
Something doesn't work
component: data grid
This is the name of the generic UI component, not the React module!
feature: Row pinning
Related to the data grid Row pinning feature
plan: Pro
Impact at least one Pro user
Duplicates
Latest version
Current behavior 😯
When using the
pinnedRows
prop in combination with thegetRowClassName
prop, therows
props cannot be an empty array.It results in:
Uncaught TypeError: Cannot read properties of null (reading 'firstRowIndex') at GridRow
... seems its trying to access a row when it shouldn't.
Using the
pinnedRows
withoutgetRowClassName
works as expected, and vice-versa.Expected behavior 🤔
We should be able to use
getRowClassName
withpinnedRows
, irrespective of whether we have any data inrows
.Steps to reproduce 🕹
Link to live example: https://codesandbox.io/s/rowpinning-demo-mui-x-forked-xjczdd?file=/demo.tsx
Steps:
pinnedRows
andgetRowClassName
props to DataGridPro componentrows
prop to an empty arrayContext 🔦
In our app, we use React Query to fetch data for the grid. React Query's
data
can beundefined
, but we feed its loading state into the grid and set rows to [] whilst it is loading (asrows
cannot beundefined
).The grid props generally look something like:
This is so that the grid has it's required rows prop whilst React Query's data is not ready to access
Its entirely possible I'm approaching this the wrong way though, but it feels like there could be any number of circumstances in which rows may be empty (hence the NoRowsOverlay)
Your environment 🌎
Tested in Chrome and Firefox
npx @mui/envinfo
Order ID 💳 (optional)
43201
The text was updated successfully, but these errors were encountered: