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] Same column in different column groups #12089

Closed
MiraHariri opened this issue Feb 16, 2024 · 8 comments
Closed

[data grid] Same column in different column groups #12089

MiraHariri opened this issue Feb 16, 2024 · 8 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Column groups Related to the data grid Column groups feature support: commercial Support request from paid users support: question Community support but can be turned into an improvement

Comments

@MiraHariri
Copy link

MiraHariri commented Feb 16, 2024

The problem in depth

I have data:

data = [
  {
    id: "1",
    cost_2022: "20",
    variation_2022_2023: "10",
    cost_2023: "30",
    variation_2023_2024: "20",
    cost_2024: "50",
  },
  {
    id: "2",
    cost_2022: "10",
    variation_2022_2023: "20",
    cost_2023: "30",
    variation_2023_2024: "10",
    cost_2024: "40",
  },
];

I want to create groups:

group = [
  {
    groupId: "2022_2023",
    headerName: "2022 - 2023 Variation",
    children: [
      { field: "cost_2022" },
      { field: "variation_2022_2023" },
      { field: "cost_2023" },
    ],
  },
  {
    groupId: "2023_2024",
    headerName: "2023 - 2024 Variation",
    children: [
      { field: "cost_2023" },
      { field: "variation_2023_2024" },
      { field: "cost_2024" },
    ],
  },
];

where the field "cost_2023" exists in both groups

How is this doable?

Your environment

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

Search keywords: Duplicate column group
Order ID: 78698

@MiraHariri MiraHariri 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 16, 2024
@michelengelen
Copy link
Member

Hey @MiraHariri ... what component are you referring to? TreeView?

And could you please provide a minimal live example? That would help us a lot in understanding your problem! Thanks! 🙇🏼

@michelengelen michelengelen added support: question Community support but can be turned into an improvement 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 16, 2024
@MiraHariri
Copy link
Author

MiraHariri commented Feb 16, 2024

@michelengelen I'm referring to columnGroupingModel

<DataGridPremium
  apiRef={apiRef}
  rows={[
    {
      id: "1",
      cost_2022: "20",
      variation_2022_2023: "10",
      cost_2023: "30",
      variation_2023_2024: "20",
      cost_2024: "50",
    },
    {
      id: "2",
      cost_2022: "10",
      variation_2022_2023: "20",
      cost_2023: "30",
      variation_2023_2024: "10",
      cost_2024: "40",
    },
  ]}
  columns={[
    {
      headerName: "ID",
      field: "id",
    },
    {
      headerName: "Cost 2022",
      field: "cost_2022",
    },
    {
      headerName: "Variation 2022 2023",
      field: "variation_2022_2023",
    },
    {
      headerName: "Cost 2023",
      field: "cost_2023",
    },
    {
      headerName: "Variation 2023 2024",
      field: "variation_2023_2024",
    },
    {
      headerName: "Cost 2024",
      field: "cost_2024",
    },
  ]}
  columnGroupingModel={[
    {
      groupId: "2022_2023",
      headerName: "2022 - 2023 Variation",
      children: [
        { field: "cost_2022" },
        { field: "variation_2022_2023" },
        { field: "cost_2023" },
      ],
    },
    {
      groupId: "2023_2024",
      headerName: "2023 - 2024 Variation",
      children: [
        { field: "cost_2023" },
        { field: "variation_2023_2024" },
        { field: "cost_2024" },
      ],
    },
  ]}
/>;


I have the field `cost_2023' is duplicated in the 2 groups

This returned an error that a field can't be in multiple groups

Is there a way to achieve this? or a workaround?

@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 16, 2024
@michelengelen
Copy link
Member

Hi @MiraHariri ... as the docs state:

:warning: a column can only be associated with one group

So, this is not possible and I am not aware of any workarounds for this. The only thing that you could do is probably duplicate that column, but from the structure of your data I would guess this can get out of hand if you scale this up, right?

@michelengelen michelengelen added status: waiting for author Issue with insufficient information feature: Column groups Related to the data grid Column groups feature component: data grid This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 19, 2024
@michelengelen michelengelen changed the title Same column in different column groups [data grid] Same column in different column groups Feb 19, 2024
@MiraHariri
Copy link
Author

Okay, yes I had this option to duplicate data with different column names in mind, and it is doable. But thought if there is a way from the table would be better

Thank you @michelengelen

@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 19, 2024
@michelengelen
Copy link
Member

Yeah ... it would have been better. If we can help you with anything else please feel free to open up a new issue! Thanks! 🙇🏼

Copy link

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @MiraHariri?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

@michelengelen michelengelen removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 19, 2024
@michelengelen
Copy link
Member

Hi @MiraHariri ... well, we can definitely improve on this. On the other hand a built-in solution should be preferred. I will try to improve the workaround, but also add this to the board for the team to build a more profound solution. 💪🏼

@michelengelen michelengelen reopened this Mar 6, 2024
@michelengelen
Copy link
Member

Sry, this is the wrong issue ... the original issue was #12222 ... closing this again

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: Column groups Related to the data grid Column groups feature support: commercial Support request from paid users support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

2 participants