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] Sort columns in column visibility panels alphabetically #15077

Open
Aberkati opened this issue Oct 23, 2024 · 5 comments
Open

[data grid] Sort columns in column visibility panels alphabetically #15077

Aberkati opened this issue Oct 23, 2024 · 5 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation enhancement This is not a bug, nor a new feature feature: Column visibility

Comments

@Aberkati
Copy link

Aberkati commented Oct 23, 2024

Steps to reproduce

Link to live example: (required)

Steps:

  1. go to mux datapremium
  2. try to manage column visibility
  3. the names of the columns are not ordered..

Current behavior

Expected behavior

Sorry for my english!
I want to sort the manage columns's panel by alphabetic order, without sorting columns of the grid.
For example :
I have 3 columns :
const columns = [
{ field: 'name', headerName: 'Name', flex: 1 },
{ field: 'age', headerName: 'Age', flex: 1 },
{ field: 'id', headerName: 'ID', flex: 1 },
];

The order of the columns displayed in the grid should be name,age,id
BUT in the column manage panel I want to have age,id,name in this order, without changing columns order in the grid

I dont found any solution in the documentation..;
thank you in advance

I have this demo but without any solutions for the moment ..
https://codesandbox.io/embed/k7p7mg?module=/src/Demo.tsx&fontsize=12

Your environment

System:
OS: Windows 10 10.0.19045
Binaries:
Node: 18.18.1 - C:\Program Files\nodejs\node.EXE
npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
pnpm: Not Found
Browsers:
Chrome: Not Found
Edge: Chromium (128.0.2739.79)
npmPackages:
@emotion/react: ^11.10.6 => 11.11.1
@emotion/styled: ^11.10.6 => 11.11.0
@mui/base: 5.0.0-beta.7
@mui/core-downloads-tracker: 5.14.0
@mui/icons-material: ^5.11.16 => 5.14.0
@mui/material: ^5.12.1 => 5.14.0
@mui/private-theming: 5.13.7
@mui/styled-engine: 5.13.2
@mui/system: 5.14.0
@mui/types: 7.2.4
@mui/utils: 5.15.14
@mui/x-data-grid: 6.20.0
@mui/x-data-grid-premium: 6.20.0 => 6.20.0
@mui/x-data-grid-pro: 6.20.0
@mui/x-license-pro: ^6.10.0 => 6.10.2
@types/react: 17.0.75
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0

Search keywords: PremiumDataGrid

Search keywords:

@Aberkati Aberkati added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 23, 2024
@oliviertassinari oliviertassinari transferred this issue from mui/material-ui Oct 23, 2024
@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Oct 23, 2024
@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 23, 2024

It looks like it's a docs problem:

SCR-20241023-ulqs
import * as React from "react";
import { DataGrid } from "@mui/x-data-grid";

export default function ColumnMenuGrid() {
  return (
    <div style={{ height: 400, width: "100%" }}>
      <DataGrid
        rows={[]}
        columns={[
          { field: "name", headerName: "Name", flex: 1 },
          { field: "age", headerName: "Age", flex: 1 },
          { field: "id", headerName: "ID", flex: 1 },
        ]}
        slotProps={{
          columnsManagement: {
            sort: "asc",
          },
        }}
      />
    </div>
  );
}

https://codesandbox.io/p/sandbox/vibrant-kalam-zvmqgv?file=%2Fsrc%2FDemo.tsx%3A4%2C1


I guess the root issue is that https://mui.com/x/api/data-grid/grid-columns-management/ doesn't exist. Is there a reason we didn't do?

diff --git a/scripts/buildApiDocs/gridSettings/index.ts b/scripts/buildApiDocs/gridSettings/index.ts
index 2da346753..11a3ce098 100644
--- a/scripts/buildApiDocs/gridSettings/index.ts
+++ b/scripts/buildApiDocs/gridSettings/index.ts
@@ -63,6 +63,7 @@ export default dataGridApiPages;
       'src/DataGridPremium/DataGridPremium.tsx',
       'src/DataGridPro/DataGridPro.tsx',
       'src/DataGrid/DataGrid.tsx',
+      'src/components/columnsManagement/GridColumnsManagement.tsx',
       'src/components/panel/filterPanel/GridFilterForm.tsx',
       'src/components/panel/filterPanel/GridFilterPanel.tsx',
       'src/components/toolbar/GridToolbarQuickFilter.tsx',

I guess that in https://mui.com/x/api/data-grid/data-grid/#DataGrid-css-MuiDataGrid-columnsManagement, those should be linked too:

SCR-20241024-bdfy

@KenanYusuf KenanYusuf changed the title The column's visibility Panel : sort alphabetic [data grid] Sort columns in column visibility panels alphabetically Oct 24, 2024
@KenanYusuf
Copy link
Contributor

@oliviertassinari we have a section on column management customization here, but it is missing the sorting option.

I think it would be better to have an API page for these options, too.

@Aberkati
Copy link
Author

Not working for my MUIX version, I'm using 6.20.0...

@michelengelen
Copy link
Member

Not working for my MUIX version, I'm using 6.20.0...

v6 still uses the columnsPanel prop as opposed to the renamed columnsManagement prop in v7. This is stated in the migration docs as well.

You can use this as an example for v6:

<DataGridPremium
  // ...
  slotProps={{
    columnsPanel: {
      sort: 'desc'
    },
  }}
/>

@michelengelen
Copy link
Member

@KenanYusuf @oliviertassinari I'll add this as a request to update the docs to the board. I do agree that we could have documented this a bit better. 👍🏼

@michelengelen michelengelen added docs Improvements or additions to the documentation enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 28, 2024
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! docs Improvements or additions to the documentation enhancement This is not a bug, nor a new feature feature: Column visibility
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

4 participants