Skip to main content

Columns Panel

The toolbar's Columns panel (show / hide, drag to reorder, pin) is also a standalone component, <GridColumnsPanel>. Put it anywhere: a sidebar, a drawer, a settings dialog. It works through the grid's apiRef, so it stays in sync with the grid and the toolbar's Columns button.

Loading demo…
import { useRef } from 'react';
import { DataTable, GridColumnsPanel, type DataTableApi } from '@ackplus/mui-tanstack-data-grid';

function UsersPage() {
const apiRef = useRef<DataTableApi<User> | null>(null);
return (
<Stack direction="row" spacing={2}>
<GridColumnsPanel apiRef={apiRef} sx={{ width: 280 }} />
<DataTable
apiRef={apiRef}
columns={columns}
data={rows}
enableColumnVisibility // show / hide toggles
enableColumnPinning // pin buttons
enableColumnReordering // drag to reorder
/>
</Stack>
);
}

How it behaves​

  • The grid decides the features. A control only appears when the grid has that feature on: no pin buttons without enableColumnPinning, and so on. The panel's own enable* props can turn a feature off for the panel (for example a panel that only shows and hides), not on.
  • Anywhere in the tree. The panel can come before or after the grid, or mount before the grid does (a lazy route, a grid behind a tab). It renders nothing until the grid is there.
  • Same strings. Labels come from the grid's localeText.
  • Themeable. The root is the columnsPanel slot: components.MuiTanstackDataGrid.styleOverrides.columnsPanel.

Props​

PropTypeDescription
apiRefRefObject<DataTableApi | null>The apiRef you pass to <DataTable>. Required.
enableColumnVisibilitybooleanfalse hides the show / hide toggles.
enableColumnPinningbooleanfalse hides the pin buttons.
enableColumnReorderingbooleanfalse turns off drag-to-reorder.
onDone() => voidShows a Done button that calls this (close your drawer).
className, sxStyle the root.

Building your own​

Need a different layout? useGridApi(apiRef) gives your component the grid's API and re-renders it after every grid change. It returns null until the grid has mounted:

import { useGridApi } from '@ackplus/mui-tanstack-data-grid';

function HiddenCount({ apiRef }) {
const api = useGridApi(apiRef);
if (!api) return null;
const hidden = api.table.getTable().getAllLeafColumns().filter((c) => !c.getIsVisible()).length;
return <Chip label={`${hidden} hidden`} onClick={() => api.columnVisibility.showAllColumns()} />;
}

apiRef.current.subscribe(listener) is the low-level form: it calls listener after every grid render and returns the unsubscribe function.