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

[data grid] Duplicating columns when grouping. #12223

Closed
RomanMain opened this issue Feb 27, 2024 · 5 comments
Closed

[data grid] Duplicating columns when grouping. #12223

RomanMain opened this issue Feb 27, 2024 · 5 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Filtering on header Related to the header filtering (Pro) feature feature: Filtering Related to the data grid Filtering feature support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ support: question Community support but can be turned into an improvement

Comments

@RomanMain
Copy link

RomanMain commented Feb 27, 2024

The problem in depth

When grouping a specific column, we have automatically generated new columns that are added to the filtering list and the “manage columns” section. Their names are completely duplicated. Is there some option to prevent these duplicate columns from appearing in these lists?

https://stackblitz.com/run?file=Demo.js

Screenshot_1
Screenshot_2

Your environment

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: grouping, duplicate columns
Order ID: 82865

@RomanMain RomanMain added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Feb 27, 2024
@zannager zannager added support: question Community support but can be turned into an improvement component: data grid This is the name of the generic UI component, not the React module! support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ labels Feb 27, 2024
@michelengelen
Copy link
Member

Hey @RomanMain and thanks for raising this issue.
It is indeed not entirely intuitive and I guess even a bug, right @MBilalShafi ?

For a workaround (and maybe for additional filtering if needed) you can use the slotProps.filterPanel.filterFormProps.filterColumns method:

const filterColumns = ({ columns }: FilterColumnsArgs) => {
  return columns.filter((column) => column.type !== 'custom').map((column) => column.field);
};

...

<DataGridPremium
  {...data}
  apiRef={apiRef}
  initialState={initialState}
  onRowSelectionModelChange={handleRowSelectionModelChange}
  rowSelectionModel={rowSelectionModel}
  checkboxSelection
  hideFooter
  slotProps={{
    filterPanel: {
      filterFormProps: {
        filterColumns,
      },
    },
  }}
/>

In this specific case we can just filter by column.type !== 'custom' since those will filter all auto generated columns by default.

I will still put this on our board to see if the current behavior is intended.
If you need additional assistance please feel free to reach out! Thanks again! 🙇🏼

@michelengelen michelengelen added bug 🐛 Something doesn't work status: waiting for author Issue with insufficient information feature: Filtering Related to the data grid Filtering feature feature: Filtering on header Related to the header filtering (Pro) feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 27, 2024
@michelengelen michelengelen changed the title [question] Duplicating columns when grouping. [data grid] Duplicating columns when grouping. Feb 27, 2024
@RomanMain
Copy link
Author

Thanks for the quick response @michelengelen! This works for the filter list, but how can I remove this in the "Manage columns" panel as well? I can’t see a slotProps similar to this in the documentation.

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Feb 27, 2024
@michelengelen
Copy link
Member

michelengelen commented Feb 27, 2024

Thanks for the quick response @michelengelen! This works for the filter list, but how can I remove this in the "Manage columns" panel as well? I can’t see a slotProps similar to this in the documentation.

No problem ... I did forget to include that.
There actually is a recipe that shows how to do this in the docs: Customize the list of columns in panel

Important

The slotProp got changed in v7
v6 => slotProps.columnsPanel.getTogglableColumns
v7 => slotProps.columnsManagement.getTogglableColumns

TLDR;

const getTogglableColumns = (columns: GridColDef[]) => {
  return columns.filter((column) => column.type !== 'custom').map((column) => column.field);
};

...

<DataGridPremium
  {...data}
  apiRef={apiRef}
  initialState={initialState}
  onRowSelectionModelChange={handleRowSelectionModelChange}
  rowSelectionModel={rowSelectionModel}
  checkboxSelection
  hideFooter
  slotProps={{
    filterPanel: {
      filterFormProps: {
        filterColumns,
      },
    },
    columnsManagement: {
      getTogglableColumns,
    },
  }}
/>

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 27, 2024
@MBilalShafi
Copy link
Member

Hey @RomanMain,

As @michelengelen mentioned, the Customize the list of columns in panel seems exactly what you are looking for. The demo depicts how to hide the status column, and the grouped column from the columns panel (v6) and columns management panel (v7).

Copy link

github-actions bot commented Mar 5, 2024

The issue has been inactive for 7 days and has been automatically closed.

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! feature: Filtering on header Related to the header filtering (Pro) feature feature: Filtering Related to the data grid Filtering feature support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ support: question Community support but can be turned into an improvement
Projects
Status: Done
Development

No branches or pull requests

4 participants