-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGrid] Add fluid columns width support #480
[DataGrid] Add fluid columns width support #480
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amiranga Does the new API solve your problem? You can preview the documentation at https://deploy-preview-480--material-ui-x.netlify.app/components/data-grid/columns/#column-fluid-width
@DanailH for the test side, this feature sounds like a (rare?) case where we could leverage unit tests on the width computation logic rather than using a full end-to-end suite. We could probably have one smoke end to end test in karma (we need to make sure the widths in pixels are correct, screenshots would be bad, and we don't need to have interactions), and cover the edge cases with unit tests? I wonder 🤔
We would need to change the demo or introduce the concept of (or at least have #416 😁) |
Yes, I agree with this and we can easily bump the minWidth. Currently its at |
Sounds like a plan. The unit tests will check if the width of the columns is calculated correctly after rendering the grid. After all the column calculation when the I'm more concerned about what should we do about the If we would want to introduce a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated, I have noticed a bug with the hover logic (persistence of hover state on mobile) can be fixed with:
diff --git a/packages/grid/_modules_/grid/components/styled-wrappers/GridRootStyles.ts b/packages/grid/_modules_/grid/components/styled-wrappers/GridRootStyles.ts
index fbe307c2..4e0f7bae 100644
--- a/packages/grid/_modules_/grid/components/styled-wrappers/GridRootStyles.ts
+++ b/packages/grid/_modules_/grid/components/styled-wrappers/GridRootStyles.ts
@@ -126,6 +126,10 @@ export const useStyles = makeStyles(
cursor: 'col-resize',
'&:hover, &.Mui-resizing': {
color: theme.palette.text.primary,
+ // Reset on touch devices, it doesn't add specificity
+ '@media (hover: none)': {
+ color: borderColor,
+ },
},
},
'& .MuiDataGrid-iconSeparator': {
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
…:DanailH/material-ui-x into feature/DataGrid-347-columns-fluid-width
…toHaveInlineStyle
Done |
Missing storybook stories. Behaviour with many cols, with just a few... What happens if we resize the cols? |
@@ -16,14 +16,47 @@ import { useApiMethod } from '../../root/useApiMethod'; | |||
import { Logger, useLogger } from '../../utils/useLogger'; | |||
import { useGridState } from '../core/useGridState'; | |||
|
|||
function mapColumns( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be selector?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep it as it is. This function is only used in the hydrateColumns
one and initially, that functionality was part of the hydrateColumns
but I separated it from it because the hydrateColumns
was becoming a bit too bloated.
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
Co-authored-by: Matt <github@nospam.33m.co>
…:DanailH/material-ui-x into feature/DataGrid-347-columns-fluid-width
@@ -115,7 +149,7 @@ const getUpdatedColumnState = ( | |||
export function useColumns(columns: Columns, apiRef: ApiRef): InternalColumns { | |||
const logger = useLogger('useColumns'); | |||
const [gridState, setGridState, forceUpdate] = useGridState(apiRef); | |||
|
|||
const viewportWidth = gridState.containerSizes ? gridState.containerSizes.viewportSize.width : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it would be better to keep the same name for variables, const containerWidth
would match its usage.
This reverts commit 4cbde43.
* [DataGrid] Add fluid columns width support * Fix doc formatting * Fix documentation so that it is complient to the MUI documentation standarts * Add unit tests * Update packages/grid/_modules_/grid/hooks/root/useColumns.ts Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com> * Update packages/grid/_modules_/grid/models/colDef/colDef.ts Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com> * Fix PR comments * Fix unit tests * Resolve TS issues * Add // @ts-expect-error need to migrate helpers to TypeScript before toHaveInlineStyle * Add storybook examples * Update docs/src/pages/components/data-grid/columns/columns.md Co-authored-by: Matt <github@nospam.33m.co> * Update docs/src/pages/components/data-grid/columns/columns.md Co-authored-by: Matt <github@nospam.33m.co> * Update docs/src/pages/components/data-grid/columns/columns.md Co-authored-by: Matt <github@nospam.33m.co> * Update docs/src/pages/components/data-grid/columns/columns.md Co-authored-by: Matt <github@nospam.33m.co> * Update docs/src/pages/components/data-grid/columns/columns.md Co-authored-by: Matt <github@nospam.33m.co> * Update packages/grid/data-grid/src/DataGrid.test.tsx Co-authored-by: Matt <github@nospam.33m.co> * Fix storybook flex col width examples * rerun ci * Fix formatting * Update docs/src/pages/components/data-grid/columns/columns.md * Trigger CI Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com> Co-authored-by: Matt <github@nospam.33m.co>
This reverts commit 4cbde43.
Sorry to be asking this here, but it seems related. Is there some sort of solution to make the XGrid table responsive by setting column priorities so that they get hidden based on their priority and width of the screen? Here is an example: http://www.primefaces.org:8080/showcase/ui/data/datatable/responsive.xhtml?jfwid=2d38a |
@AleKrabbe Please open a new issue, it's not related to this effort. Currently, you can implement this with the useMediaQuery helper to match specific breakpoints. |
This PR aims to provide support for fluid / responsive columns. This is achieved by setting a
flex
property on a column definition. Theflex
property can work together with thewidth
property.I've tested a couple of data grids to benchmark the functionality and the one that seemed the most intuitive was the one that ag-Grid provides.
The default functionality is not affected by this change. The fluid columns will only work if a user sets the
flex
optional property in the column definition.Limitations: Currently if you resize a column with flex and you resize the entire page the sizes of all columns are returned to their original state (this is also the current behavior)
PS: Although this solution works if we decide to go with a different public API I will change it.
Fixes #347