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] Is there a way to get the features of footer to the toolbar? #16323

Open
ZaidLinkEZ opened this issue Jan 24, 2025 · 2 comments
Open
Labels
component: data grid This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@ZaidLinkEZ
Copy link

ZaidLinkEZ commented Jan 24, 2025

The problem in depth

I wanted to know if the footer details can be brought up to the toolbar, basically like a header of the table beside the toolbar functions. For ex: Selected Rows : , Total Rows: , etc.
If not, is it a feature that you are looking forward to bring to the library?

Your environment

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

Search keywords: Data grid pro

Order ID: 95670

@ZaidLinkEZ ZaidLinkEZ added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Jan 24, 2025
@github-actions github-actions bot added component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ labels Jan 24, 2025
@KenanYusuf
Copy link
Member

Hi @ZaidLinkEZ.

You would need create a custom toolbar and pass it to the toolbar slot. Inside the custom toolbar, you can use useGridSelector and the relevant selector to get the information you want to show.

import * as React from "react";
import {
  DataGrid,
  GridToolbarContainer,
  selectedGridRowsCountSelector,
  gridTopLevelRowCountSelector,
  gridFilteredTopLevelRowCountSelector,
  useGridSelector,
  useGridApiContext,
} from "@mui/x-data-grid";
import Typography from "@mui/material/Typography";

function CustomToolbar() {
  const apiRef = useGridApiContext();
  const selectedRows = useGridSelector(apiRef, selectedGridRowsCountSelector);
  const totalRows = useGridSelector(apiRef, gridTopLevelRowCountSelector);
  const visibleRows = useGridSelector(
    apiRef,
    gridFilteredTopLevelRowCountSelector
  );

  return (
    <GridToolbarContainer>
      <Typography>Selected rows: {selectedRows}</Typography>
      <Typography>Total rows: {totalRows}</Typography>
      <Typography>Visible rows: {visibleRows}</Typography>
    </GridToolbarContainer>
  );
}

export default function CustomToolbarGrid() {
  return (
    <DataGrid
      slots={{ toolbar: CustomToolbar }}
    />
  );
}

Here's a working example in CodeSandbox https://codesandbox.io/p/sandbox/data-grid-footer-data-in-toolbar-h6x9xd.

You can find the available state selectors here: https://mui.com/x/react-data-grid/state/#catalog-of-selectors

@michelengelen
Copy link
Member

Here is an example on how you can add similar stuff to the toolbar as well: #16132

@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 Jan 24, 2025
@michelengelen michelengelen changed the title [question] Data Grid Pro: Is there a way to get the features of footer to the toolbar? [data grid] Is there a way to get the features of footer to the toolbar? Jan 24, 2025
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! status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/
Projects
None yet
Development

No branches or pull requests

3 participants