[DataGrid] Expandable rows #5638
-
On occasion, teams have expressed a need for expandable rows in the data grid. While not depicted in this exact PR, the future desire here is to expose additional metadata in a row while taking advantage of the other pros of using data grid (i.e. scalability, column selection, advanced sorting, etc.). Also in the area of alerting, the Security team has expressed similar desires for an expandable row. As the topic has come up more than once, we are curious to get the EUI team's take on possibility of adding this feature to the data grid.
|
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 31 replies
-
🚀 We are currently putting together a spec for how expandable rows could/should work, and expect to have that ready for review some time next week. Once everyone agrees on the spec we can figure out how to split up implementation efforts. |
Beta Was this translation helpful? Give feedback.
-
UX questions
|
Beta Was this translation helpful? Give feedback.
-
API questions/proposalsWhat should the DataGrid's API for this look like? A couple examples/proposals off the top of my head:
<EuiDataGrid
expandedRowMap={{
0: <SomeExpandedContent />,
2: <OtherExpandedContent />,
}}
/>
// This feels similar to EuiBasicTable's `itemIdToExpandedRowMap`
// Is this too simplistic? No way of passing props to the expanded rows. Or maybe that isn't necessary?
<EuiDataGrid
renderExpandedRow={({ rowIndex, isExpanded }) => {
if (rowIndex === 3) return <SomeExpandedContent />;
return <OtherExpandedContent />;
}}
/>
// Similar approach to `renderCellValue` and `renderCellPopover` fns, allows us to pass props/info a component passed by the consumer
|
Beta Was this translation helpful? Give feedback.
-
Accessibility questionsCCing @1Copenut on this for any expertise he might have on tables/grids with expanded rows and if W3 has a spec for it & how they should behave for screen readers. Expanded row behavior is somewhat broken in EuiBasicTable - once a row is expanded, its original data cells can no longer be reached by SR arrow navigation. I strongly feel that if we implement expanded rows in EuiDataGrid, they should be fully keyboard and screen reader accessible; we have worked hard as a team to continuously improve data grid's accessibility and I'd really like to keep it that way.
|
Beta Was this translation helpful? Give feedback.
-
Technical approach & suggestionsVirtualizationTo fully understand the technical challenge of expandable rows, you must first understand how Data Grid's virtualization library (react-window) works. I recommend taking a look at their VariableSizeGrid example, scrolling around, and inspecting the DOM of each cell. Once you do, several things become apparent:
RenderingOK, now that our row & cell heights and positions are in the right ballpark of where we want them, we now need to render the row expansion content itself. My first instinctual approach would be to bundle the row expansion toggle and the row expansion content together within one "cell". The alternative would be to attempt to render the expansion toggle & content as 2 separate cells, which has potentially gnarly side effects on the underlying grid (column counts are now "slightly" off by 1 invisible 'column', which can then affect keyboard navigation, etc) so if possible I'd rather try to keep the toggle (visible cell) and the content (conditionally hidden) conceptually together. Here's a rough visual mock of what I'm thinking, based on EuiBasicTable: Moving ahead with the bundled approach: if we treat the row expansion toggle as a special Let me know if that doesn't make sense. Again, I think this is the simplest way to handle rendering the expanded content, but I could be off the mark here for a few reasons (DOM complications, accessibility considerations, etc.), so this may be the area we most need to revisit or troubleshoot. StateOK, so now we have virtualization positioning and rendering (sort of) out of the way - how do we know which row(s) should be open and which should be closed? Assuming multiple rows can be expanded (see UX question 2), I would suggest an const [expandedRowMap, setExpandedRowMap] = useState({ 0: true }); // Maybe allow passing an initialExpandedRowMap?
const expandRow = useCallback((rowIndex: number) => {
setExpandedRowMap((expandedRowMap) => { ...expandedRowMap, [rowIndex]: true });
}, []);
const collapseRow = useCallback((rowIndex: number) => {
setExpandedRowMap((expandedRowMap) => { ...expandedRowMap, [rowIndex]: false });
}, []); This state must exist at the If we need to expose some sort of Also worth noting and QAing for - we should ensure we are using the Questions?Have I missed a consideration (very likely)? Leave a comment if so! |
Beta Was this translation helpful? Give feedback.
-
I'm working on a few things today so I can really focus on this discussion and offer useful a11y guidance. Hope to have that out before end of week. |
Beta Was this translation helpful? Give feedback.
-
@gmmorris I would be curious to hear your thoughts from the ResponsOps side regarding:
Perhaps there is an alternative approach here where the features you seek from data grid could be supported by existing table components which already support expandable rows... I'm envisioning the bulk edit bar enhancements. It seems we're all trying to find the line of what makes a data grid a data grid and where we may just be blending things to the point we lose their specialties. |
Beta Was this translation helpful? Give feedback.
-
@andrew-goldstein @michaelolo24 - I know it's been... almost literally a year since we've talked about this (based on the GH discussion timestamps - although I know we've chatted about this more recently than that) - but I wanted to quickly highlight an open PR that will enable your team to layout your own custom expandable rows: #6624 Staging example: https://eui.elastic.co/pr_6624/#/tabular-content/data-grid-advanced#custom-body-renderer Check the "toggle row details" switch: The major tradeoff to this API is that you lose built-in virtualization (so may not be performant depending on the # of rows being displayed per page), and you are completely in charge of laying out cells. I've built the staging example to be as close to the usage that (I think) y'all wanted as possible, so that part hopefully shouldn't be a major issue, but I'd love to get feedback from your team and whether it will either meet or your needs or need to be tweaked before merging this in. |
Beta Was this translation helpful? Give feedback.
@andrew-goldstein @michaelolo24 - I know it's been... almost literally a year since we've talked about this (based on the GH discussion timestamps - although I know we've chatted about this more recently than that) - but I wanted to quickly highlight an open PR that will enable your team to layout your own custom expandable rows: #6624
Staging example: https://eui.elastic.co/pr_6624/#/tabular-content/data-grid-advanced#custom-body-renderer
Check the "toggle row details" switch:
The major tradeoff to this API is that you lose built-in virtualization (so may not be performant depending on the # of rows being displayed per page), and you are completely in charge of laying out cells. I've bu…