Skip to content
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] Allow to pass csvOptions and printOptions to GridToolbar #3623

Merged
merged 13 commits into from Jan 20, 2022

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Jan 14, 2022

Custom CSV export seems to be a pretty common use can. For me it feels wrong that users have to override the whole toolbar in order to apply the slightest customization (ex: #3563, #3064, #2860, #2156, ...)

Even the doc was dodging the question by creating a very incomplete GridToolbar without the other built-in buttons.
But most of the time, users just want to customize the CSV and/or print export, not to loose all the other features of the GridToolbar.

I added csvOptions and printOptions to GridToolbar and just forward them to GridToolbarExport which makes everything a lot easier

Before:

const CustomToolbar = React.forwardRef<HTMLDivElement, GridToolbarProps>(function GridToolbar(
  props,
  ref,
) {
  const { className, csvOptions, printOptions, ...other } = props;
  const rootProps = useGridRootProps();

  if (
    rootProps.disableColumnFilter &&
    rootProps.disableColumnSelector &&
    rootProps.disableDensitySelector
  ) {
    return null;
  }

  return (
    <GridToolbarContainer ref={ref} {...other}>
      <GridToolbarColumnsButton />
      <GridToolbarFilterButton />
      <GridToolbarDensitySelector />
      <GridToolbarExport csvOptions={{ delimited: ';' }} />
    </GridToolbarContainer>
  );
});

const CustomDataGrid = (props: DataGridProps) => {
  return (
    <DataGrid {...props} components={{ Toolbar: CustomToolbar }} />
  )
}

After:

const CustomDataGrid = (props: DataGridProps) => {
  return (
    <DataGrid {...props} componentsProps={{ toolbar: { csvOptions: { delimiter: ';' }} />
  )
}

Other changes

  • Add basic tests for CSV export at the UI level (we only had unit test on the export method)
  • Reformulate the doc page to better explain the various level of customization

@flaviendelangle flaviendelangle self-assigned this Jan 14, 2022
@flaviendelangle flaviendelangle added the component: data grid This is the name of the generic UI component, not the React module! label Jan 14, 2022
@mui-bot
Copy link

mui-bot commented Jan 14, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 208.1 402.6 292 303.62 80.223
Sort 100k rows ms 335.6 870.6 502 571.88 190.092
Select 100k rows ms 157.7 324.1 246 237.94 55.317
Deselect 100k rows ms 128.2 188.6 151 158 22.168

Generated by 🚫 dangerJS against 170c4d8

@flaviendelangle flaviendelangle marked this pull request as ready for review January 14, 2022 12:18
@m4theushw m4theushw self-requested a review January 19, 2022 16:02
Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left only a few suggestions for the documentation. Looks good.

docs/src/pages/components/data-grid/export/export.md Outdated Show resolved Hide resolved
docs/src/pages/components/data-grid/export/export.md Outdated Show resolved Hide resolved
docs/src/pages/components/data-grid/export/export.md Outdated Show resolved Hide resolved
docs/src/pages/components/data-grid/export/export.md Outdated Show resolved Hide resolved
flaviendelangle and others added 4 commits January 20, 2022 10:36
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
flaviendelangle and others added 3 commits January 20, 2022 13:03
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
Co-authored-by: Matheus Wichman <matheushw@outlook.com>
@flaviendelangle flaviendelangle merged commit ed223c3 into mui:master Jan 20, 2022
@flaviendelangle flaviendelangle deleted the export-toolbar-props branch January 20, 2022 12:41
@oliviertassinari oliviertassinari added the new feature New feature or request label Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants