Guides
Toolbar Customization Guide
How to customize the Toolbars, add buttons to toolbars, or customize progress bars and alert banners in Shadcn Table
This guide shows you how to hide, customize, or override the top and bottom toolbars in Shadcn Table.
Example
Relevant Table Options
| Prop Name | Type | Description |
|---|---|---|
| enableBottomToolbar | boolean | |
| enableSortPopover | boolean | Adds the sort button to the toolbar. It opens the sort editor, where the user adds, reorders and removes sort rules. |
| enableToolbarInternalActions | boolean | |
| enableTopToolbar | boolean | |
| enableViewSettings | boolean | Adds the view settings button to the toolbar. Its panel holds Columns, Density, Wrap cell text, Grid lines, Sticky header, Alternating row colors, Row numbers and Reset view; pinned items show as toolbar buttons. |
| positionGlobalFilter | 'left' | 'right' | |
| positionPagination | 'bottom' | 'top' | 'both' | |
| positionToolbarAlertBanner | 'bottom' | 'top' | 'none' | |
| positionToolbarDropZone | 'bottom' | 'top' | 'both' | 'none' | |
| renderBottomToolbar | ReactNode | ({ table }) => ReactNode | |
| renderBottomToolbarCustomActions | ({ table }) => ReactNode | |
| renderToolbarAlertBannerContent | ({ table, groupedAlert, selectedAlert }) => ReactNode | |
| renderToolbarInternalActions | ({ table}) => ReactNode | |
| renderTopToolbar | ReactNode | ({ table }) => ReactNode | |
| renderTopToolbarCustomActions | ({ table }) => ReactNode | |
| stBottomToolbarProps | BoxProps | ({ table }) => BoxProps | |
| stLinearProgressProps | LinearProgressProps | ({ isTopToolbar, table }) => LinearProgressProps | |
| stToolbarAlertBannerChipProps | ChipProps| ({ table }} => ChipProps | |
| stToolbarAlertBannerProps | AlertProps | ({ table }) => AlertProps | |
| stTopToolbarProps | BoxProps | ({ table }) => BoxProps |
Relevant State
| State Option | Type | Description |
|---|---|---|
| showAlertBanner | boolean | |
| showProgressBars | boolean | Unset by default, so it follows isSaving until it is set. false turns it off. |
Toolbar Layout
The top toolbar is a plain row above the bordered table frame; the frame holds the scrolling table and the bottom toolbar. On the left of the top toolbar sit the sort chip, the filter chips and anything you render with renderTopToolbarCustomActions. On the right sits one group of built-in buttons, in this order:
- The search field and its toggle (Global Filtering Guide). The field opens inline to the left of the group.
- The filter button, which opens the "Filter by..." column picker (with
columnFilterDisplayMode: 'subheader', the show/hide filters toggle instead). - The sort button, which opens the sort editor.
- The view settings items pinned to the toolbar (Columns and Density by default).
- The full screen toggle.
- The view settings button.
The buttons are small ghost icon buttons. The filter button turns to the secondary fill while any filter chip exists and the sort button while any sort exists; the search, full screen, view settings and pinned buttons stay ghost and show their state through their icon. With enableViewSettings: false, the separate columns button and density toggle return in place of the pinned items and the view settings button.
Hide or Disable Toolbars
There are enableTopToolbar and enableBottomToolbar table options that you can use to show or hide the toolbars.
const table = useShadcnTable({
data,
columns,
enableTopToolbar: false,
enableBottomToolbar: false,
});
return <ShadcnTable table={table} />;Alternatively, you could just use a different ST component that does not have the toolbars built-in. For example, use the <ST_TableContainer /> or <ST_Table /> components instead of the <ShadcnTable /> component.
const table = useShadcnTable({
data,
columns,
});
//This ST sub-component does not contain the code for the toolbars. ST_TableLayout and ShadcnTable do.
return (
<ST_TableProvider table={table}>
<ST_TableContainer />
</ST_TableProvider>
);Sub-components rendered outside <ShadcnTable /> read the table from an ST_TableProvider. See Compose with ST_TableProvider.
No Toolbars Example
Customize Toolbar buttons
Everything in the toolbars are customizable. You can add your own buttons or change the order of the built-in buttons.
Customize Built-In Internal Toolbar Button Area
The renderToolbarInternalActions table option allows you to redefine the built-in buttons that usually reside in the top right of the top toolbar. You can reorder the icon buttons or even insert your own custom buttons. All of the built-in buttons are available to be imported from '@/components/ui/shadcn-table'.
import {
ShadcnTable,
ST_SortPopover,
ST_ShowHideColumnsButton,
ST_ToggleFullScreenButton,
ST_ToggleGlobalFilterButton,
ST_ViewSettingsButton,
} from '@/components/ui/shadcn-table';
const table = useShadcnTable({
data,
columns,
renderToolbarInternalActions: ({ table }) => (
<>
{/* add your own custom print button or something */}
<IconButton onClick={() => showPrintPreview(true)}>
<PrintIcon />
</IconButton>
{/* built-in buttons (they read the table from ShadcnTable) */}
<ST_ToggleGlobalFilterButton />
<ST_ShowHideColumnsButton />
<ST_ToggleFullScreenButton />
{/* the v0.8 toolbar components take the table as a prop */}
<ST_SortPopover table={table} />
<ST_ViewSettingsButton table={table} />
</>
),
});
return <ShadcnTable table={table} />;ST_ViewSettingsItems renders the pinned view settings buttons and ST_FilterChips the chips row; both take the table prop as well.
Add Custom Toolbar Buttons/Components
The renderTopToolbarCustomActions and renderBottomToolbarCustomActions table options allow you to add your own custom buttons or components to the top and bottom toolbar areas. These props are functions that return a ReactNode. You can add your own buttons or whatever components you want.
In all of these render... table options, you get access to the table instance that you can use to perform actions or extract data from the table.
const table = useShadcnTable({
data,
columns,
enableRowSelection: true,
//Simply adding a table title to the top-left of the top toolbar
renderTopToolbarCustomActions: () => (
<Typography variant="h3">Customer's Table</Typography>
),
//Adding a custom button to the bottom toolbar
renderBottomToolbarCustomActions: ({ table }) => (
<Button
variant="contained"
color="lightblue"
//extract all selected rows from the table instance and do something with them
onClick={() => handleDownloadRows(table.getSelectedRowModel().rows)}
>
Download Selected Rows
</Button>
),
});
return <ShadcnTable table={table} />;Custom Toolbar Actions Example
Position Toolbar Areas
The positionToolbarAlertBanner, positionGlobalFilter, positionPagination, and positionToolbarDropZone table options allow you to swap the default position of certain areas of the toolbars. Experiment moving them around until you find a layout that works for you.
const table = useShadcnTable({
data,
columns
//if rendering top toolbar buttons, sometimes you want alerts to be at the bottom
positionToolbarAlertBanner: 'bottom',
positionGlobalFilter: 'left', //move the search box to the left of the top toolbar
positionPagination: 'top',
renderTopToolbarCustomActions: () => <span>...</span>,
});
return <ShadcnTable table={table} />;Customize Toolbar Props and Styles
The stTopToolbarProps, stBottomToolbarProps, stToolbarAlertBannerProps, and stToolbarAlertBannerChipProps table options allow you to customize the props and styles of the underlying shadcn/ui components that make up the toolbar components. Remember that you can pass CSS overrides to their className or style props. Some have found this useful for forcing position: absolute on alerts, etc.
Customize Linear Progress Bars
The progress bars that display in both the top and bottom toolbars become visible when either the isLoading or showProgressBars state options are set to true. You can customize the progress bars by passing in props to the stLinearProgressProps table option. By default, the progress bars have a full animated progress bar, but you can set the value table option to a number between 0 and 100 to show real progress values if your table is doing some complicated long running tasks that you want to show progress for. Visit the shadcn/ui Progress docs to learn more.
const table = useShadcnTable({
data,
columns,
stLinearProgressProps: ({ isTopToolbar }) => ({
progressComponentProps: {
className: '[&>[data-slot=progress-indicator]]:bg-amber-500',
style: { display: isTopToolbar ? 'block' : 'none' }, //only show top toolbar progress bar
value: fetchProgress, //show precise real progress value if you so desire
},
}),
state: {
isLoading,
showProgressBars,
},
});
return <ShadcnTable table={table} />;Customize Toolbar Alert Banner
The toolbar alert banner is an internal component used to display alerts to the user. By default, it will automatically show messages around the number of selected rows or grouping state.
However, you can repurpose this alert banner to show your own custom messages too. You can force the alert banner to show by setting the showAlertBanner state option to true. You can then customize the messages and other stylings using the stToolbarAlertBannerProps to create your custom message. You probably saw this in the Remote Data or React Query examples.
const table = useShadcnTable({
data,
columns,
//show a custom error message if there was an error fetching data in the top toolbar
stToolbarAlertBannerProps: isError
? {
className: 'border-destructive text-destructive',
children: 'Network Error. Could not fetch data.',
}
: undefined,
state: {
showAlertBanner: isError,
showProgressBars: isFetching,
},
});
return <ShadcnTable table={table} />;Override with Custom Toolbar Components
If you want to completely override the default toolbar components, you can do so by passing in your own custom components to the renderTopToolbar and renderBottomToolbar props.
The drawback to this approach is that you will not get all the automatic features of the default toolbar components, such as the automatic alert banner, progress bars, etc. You will have to implement all of that yourself if you still want those features. Though you can also just import those ST components and use them in your custom toolbar.
import {
ST_GlobalFilterTextField, //import ST sub components!
ST_TablePagination,
ShadcnTable,
useShadcnTable,
} from '@/components/ui/shadcn-table';
const table = useShadcnTable({
data,
columns,
renderTopToolbar: () => (
<span className="flex items-center justify-between">
<ST_GlobalFilterTextField />
<ST_TablePagination />
</span>
),
renderBottomToolbar: ({ table }) => (
<span>
<Button>Download</Button>
</span>
),
});
return <ShadcnTable table={table} />;Build Your Own Toolbar
Instead of overriding the toolbar components up above, you may want 100% control over the layout and styling of your table controls and where they are on the page. You can do this by just using a ST sub component such as <ST_TableContainer /> for the table component, which does not have the internal toolbar components built-in. Optionally, build your own custom toolbar components using the other ST sub components.
Compose with ST_TableProvider
<ShadcnTable /> puts its table on a context that every ST sub-component reads, so most sub-components take no table prop (the toolbar components ST_SortPopover, ST_FilterChips, ST_ViewSettingsButton, ST_ViewSettingsItems and ST_ScrollButtons take it explicitly). Inside render... table options and custom Cell or Header renders, they work as is. Anywhere else, wrap them in ST_TableProvider:
import {
ST_GlobalFilterTextField,
ST_TableContainer,
ST_TablePagination,
ST_TableProvider,
useShadcnTable,
} from '@/components/ui/shadcn-table';
const table = useShadcnTable({ columns, data });
return (
<ST_TableProvider table={table}>
<ST_GlobalFilterTextField />
<ST_TableContainer />
<ST_TablePagination />
</ST_TableProvider>
);ST_TableProvider follows the table prop. A different table remounts the provider's subtree.