mui-react-data-grid v0.0.1
The MuiReactDataGrid component is a feature-rich and customizable data grid designed for React applications, providing developers with powerful tools to manage and display tabular data efficiently. It supports advanced functionalities like cell click events, sticky headers, serial number columns, and pagination.
With its highly configurable options
object, developers can customize the grid's appearance and behavior. Features include column filtering, sorting, and flexible toolbar options for column arrangement, bulk Freeze/delete, and data upload/download. The grid also supports currency formatting, text ellipsis, and responsive row actions like edit, delete, or view details, complete with tooltips and icons.
Additional highlights include dynamic row heights, date formatting, and customizable header/footer colors to match your application's theme. Install and use MuiReactDataGrid
to simplify data handling and visualization in your React projects.
Installation
Install the package with npm:
npm i mui-react-data-grid
Example
<MuiAdvancedDataGrid
data={[]}
isLoading={isLoading}
columns={columns}
childrens={children}
options={{
enableCellClick: true,
height: 600,
enableStrikyHeader: true,
headerBackgroundColor: '#eef6ff',
footerBackgroundColor: '#eef6ff',
dateFormat: 'DD/MM/YYYY HH:mm:ss',
textEllipsis: 10,
enableSerialNumber: true,
color: 'success',
currencyOptions: {
currencyCode: 'USD',
locale: 'en-US',
decimal: 2,
},
filterOptions: {
variant: 'standard',
enableMultipleColumnSelection: true,
onQuerySearch,
},
paginationOptions: {
pageSize: 0,
rowPerPage: [50, 100, 150],
isFirstLastPageButton: false,
},
toolbarOptions: {
enableColumnArrangement: true,
enableDeleteAll: true,
ToolbarComponent: <Button>Test<Button>,
onUpload,
onDownload,
},
rowActions: [
{
label: 'Edit',
icon: <EditIcon />,
tooltip: 'Edit',
onClick: (row) => {
console.log('Edit action clicked for row:', row);
},
},
],
}}
/>
Documentation
data
:- Purpose: Provides the data to be displayed in the grid.
- Type: Array of objects.
- Example:
const listArray = [ { id: 1, name: 'John Doe', age: 30 }, { id: 2, name: 'Jane Smith', age: 25 }, ];
isLoading
:- Purpose: Indicates whether the grid is in a loading state.
- Type: Boolean.
- Example: Set
isLoading={true}
to show a loading skeleton while data is being fetched.
columns
:- Purpose: Defines the structure and headers of the grid.
- Type: Array of objects.
- Example:
const columns = [ { field: 'id', headerName: 'ID', width: 70 }, { field: 'name', headerName: 'Name', width: 150 }, { field: 'age', headerName: 'Age', width: 100 }, ];
childrens
:- Purpose: Defines the structure and headers of the grid.
- Type: Array of objects.
- Example:
const columns = [ { field: 'address', headerName: 'Address', width: 70 }, ];
options
Property
The options
object is used to configure various settings and behaviors for the grid.
enableCellClick
:- Purpose: Enables clicking on cells to trigger events.
- Type: Boolean.
- Example: Set
enableCellClick={true}
to allow cell click handling.
height
:- Purpose: Sets the height of the grid.
- Type: Number (pixels).
- Example:
height: 600
sets the grid height to 600 pixels.
enableStrikyHeader
:- Purpose: Enables a sticky header that stays visible while scrolling.
- Type: Boolean.
- Example: Set
enableStrikyHeader={true}
to keep the header fixed.
headerBackgroundColor
andfooterBackgroundColor
:- Purpose: Sets custom colors for the header and footer.
- Type: String (CSS color values).
- Example:
headerBackgroundColor: '#eef6ff'
.
dateFormat
:- Purpose: Specifies the date format for date fields in the grid.
- Type: String.
- Example:
dateFormat: 'DD/MM/YYYY HH:mm:ss'
.
textEllipsis
:- Purpose: Limits the number of characters shown in a cell, with ellipsis for overflow.
- Type: Number.
- Example:
textEllipsis: 10
truncates text longer than 10 characters.
enableSerialNumber
:- Purpose: Adds a serial number column to the grid.
- Type: Boolean.
- Example: Set
enableSerialNumber={true}
to show row numbers.
color
:- Purpose: Sets a theme color for the grid.
- Type: String.
- Example:
color: 'success'
.
currencyOptions
currencyCode
:- Purpose: Defines the currency type for formatting monetary values.
- Type: String.
- Example:
currencyCode: 'USD'
.
locale
:- Purpose: Sets the locale for currency formatting.
- Type: String.
- Example:
locale: 'en-US'
.
decimal
:- Purpose: Specifies the number of decimal places.
- Type: Number.
- Example:
decimal: 2
.
filterOptions
variant
:- Purpose: Specifies the filter style.
- Type: String (
'standard'
,'outlined'
,'filled'
). - Example:
variant: 'standard'
.
enableMultipleColumnSelection
:- Purpose: Allows filtering on multiple columns.
- Type: Boolean.
- Example:
enableMultipleColumnSelection: true
.
onQuerySearch
:- Purpose: Callback function triggered when a filter is applied.
- Type: Function.
paginationOptions
pageSize
:- Purpose: Specifies the default number of rows per page.
- Type: Number.
- Example:
pageSize: 0
(default shows all rows).
rowPerPage
:- Purpose: Array of available options for rows per page.
- Type: Array of Numbers.
- Example:
[50, 100, 150]
.
isFirstLastPageButton
:- Purpose: Enables or disables buttons to jump to the first and last pages.
- Type: Boolean.
- Example:
isFirstLastPageButton: false
.
toolbarOptions
enableColumnArrangement
:- Purpose: Allows reordering or hiding columns.
- Type: Boolean.
- Example:
enableColumnArrangement: true
.
enableDeleteAll
:- Purpose: Adds a button to delete all rows.
- Type: Boolean.
- Example:
enableDeleteAll: true
.
ToolbarComponent
:- Purpose: Custom toolbar component.
- Type: React Component or
undefined
.
onUpload
andonDownload
:- Purpose: Callbacks for uploading or downloading data.
- Type: Functions.
rowActions
- Purpose: Adds action buttons for each row.
- Type: Array of objects.
- Example:
rowActions: [ { label: 'Edit', icon: <EditIcon />, onClick: (row) => { console.log('Edit clicked for row:', row); }, tooltip: 'Edit', }, ];
Authors
- Shivaji : (Sr. React Developer)
- Shyamal : (Sr. React Developer)
License
4 months ago