Skip to main content

Documentation

Our DataGrid is based on MUI's DataGrid, and you can find the documentation here: https://mui.com/x/react-data-grid/

We've added some custom props :

  • to the DataGrid component
  • in the slot toolbar of the DataGrid component to mimic Virtual Table toolbar

Custom DataGrid props

NameTypeRequiredDefaultDescription
rowContextMenuobjectNoConfiguration object to enable and customize a context menu shown when right-clicking a row.

rowContextMenu

NameTypeRequiredDefaultDescription
canOpenfunctionNoCallback that determines whether the context menu should open. Receives the selected rows as an argument and should return true to allow the menu or false to prevent it.
actionsarrayYesArray of action definitions to be displayed in the context menu.
rowContextMenu.actions
NameTypeRequiredDefaultDescription
keystringYesUnique identifier for the action.
labelstringYesText label displayed for the action.
disabledboolean | functionNofalseDisables the action if true. If a function is provided, it will be called with the selected rows and should return a boolean.
onClickfunctionYesCallback triggered when the action is clicked. Receives the selected rows as an argument.

Custom SlotProps.toolbar props

NameTypeRequiredDefaultDescription
customButtonsarrayNoDisplay custom buttons to the left of the right-side button area.
deleteActionobjectNoEnables deletion and displays the delete button after the custom buttons.
bulkEditActionobjectNoEnables bulk editing and displays save and cancel buttons after the custom buttons.
exportHandlersarrayNoEnables the Export toolbar button with a dropdown menu. See Export (CSV and Excel) below.
showSelectedCountbooleanNotrueShow selected count

customButtons

NameTypeRequiredDefaultDescription
keystring | numberYesUnique identifier for the button, also used to generate the data-id attribute.
type'text' | 'icon'No'text'Defines whether the button displays text or an icon.
- textstringYesThe button label, used when type is set to 'text'.
- iconcomponentYesThe icon component to display when type is set to 'icon'.
colorButtonProps['color']No'primary'Sets the button color, based on MUI's color palette.
disabledbooleanNofalseIf true, the button is disabled.
onClickfunctionYesCallback triggered on button click. Receives selected row IDs and selected row data as arguments.

deleteAction

NameTypeRequiredDefaultDescription
disabledbooleanNofalseIf true, the button is disabled.
onDeletefunctionYesCallback triggered on button click. Receives selected row IDs and returns a boolean indicating success, used to automatically unselect the rows if success.

bulkEditAction

NameTypeRequiredDefaultDescription
disabledbooleanNofalseIf true, the button is disabled.
onBulkEditSavefunctionYesCallback triggered on button click. Receives selected row IDs and new rows and returns a boolean indicating success, used to automatically unselect the rows if success or cancel modification if not.
NameTypeRequiredDefaultDescription
keystringYesUnique identifier for the action, also used to generate the data-id attribute.
labelstringYesThe action label.
iconcomponentNoThe icon component to display.
colorstringNo'primary.main'The action color.
disabledboolean | functionNofalseDisables the action if true. If a function is provided, it will be called with the selected rows and should return a boolean.
onClickfunctionYesCallback triggered when the action is clicked. Receives the selected rows as an argument.

exportHandlers

Enables an Export button in the toolbar. Clicking it opens a dropdown menu (MUI default) with the export options you provide. Each option is defined by a handler that calls the grid API or your custom export logic.

NameTypeRequiredDescription
type'csv' | 'xls'YesExport format identifier. 'csv' for CSV, 'xls' for Excel (.xlsx).
handlerfunctionYesCallback that performs the export. Typically calls apiRef.current?.exportDataAsCsv() or exportDataAsXlsx().

Example:

import DataGridDS, {
attachExcelExportToApi,
type ExportHandler
} from '@myunisoft/design-system';
import { useGridApiRef } from '@mui/x-data-grid-pro';

function MyGrid() {
const apiRef = useGridApiRef();
const fileName = 'my-export';

const exportHandlers: ExportHandler[] = [
{
type: 'csv',
handler: () => apiRef.current?.exportDataAsCsv({ fileName })
},
{
type: 'xls',
handler: () => {
const api = apiRef.current;
(api as typeof api & { exportDataAsXlsx?: (opts?: { fileName?: string }) => void })
?.exportDataAsXlsx?.({ fileName });
}
}
];

return (
<DataGridDS
apiRef={apiRef}
columns={columns}
rows={rows}
slotProps={{ toolbar: { exportHandlers } }}
/>
);
}

Export (CSV and Excel)

  • CSV: MUI DataGrid Pro provides CSV export via the grid API (exportDataAsCsv). In your exportHandlers, pass a handler that calls apiRef.current?.exportDataAsCsv({ fileName }) to download the grid data as a .csv file.

  • Excel (.xlsx): MUI DataGrid Pro does not provide Excel export. The design system adds it:

    • In the toolbar: If you include 'xls' in exportHandlers with a handler that calls exportDataAsXlsx, the toolbar uses our internal Excel export (via ExcelJS) to download the grid data as a .xlsx file.
    • Programmatic use: You can attach an exportDataAsXlsx method to the grid API. Import attachExcelExportToApi from the package and call it with the grid's apiRef:
import DataGridDS, { attachExcelExportToApi } from '@myunisoft/design-system';
import { useGridApiRef } from '@mui/x-data-grid-pro';

function MyGrid() {
const apiRef = useGridApiRef();
// DataGridDS calls attachExcelExportToApi internally when the grid is ready.
// Or call it yourself: attachExcelExportToApi(apiRef, 'my-file');
return (
<DataGridDS apiRef={apiRef} columns={columns} rows={rows} />
);
}
// Then elsewhere: apiRef.current?.exportDataAsXlsx({ fileName: 'my-export' });

attachExcelExportToApi(apiRef, fileName?) adds exportDataAsXlsx(options?: { fileName?: string }) to the grid API. The default file name is the one you pass or 'export'. The actual export is implemented in the DataGrid utils and uses the grid's getDataAsCsv plus ExcelJS to produce the .xlsx file.