mui-datatables, react-data-table-component, and react-table represent three distinct approaches to handling tabular data in React. react-table is a headless utility library that provides logic hooks (like useTable) without rendering any UI, giving developers full control over markup and styling. mui-datatables is an integrated solution built specifically for Material-UI (MUI), offering a complete grid component with built-in theming and features like filtering and pagination. react-data-table-component is a standalone, opinionated component library that requires no specific CSS framework, providing a ready-to-use table with extensive built-in functionality and conditional styling.
When building data-heavy applications, the choice of a table library often dictates your architecture, styling strategy, and long-term maintenance burden. The three libraries in question—mui-datatables, react-data-table-component, and react-table—solve the same problem but follow fundamentally different design philosophies. Understanding these differences is crucial for making the right architectural decision.
The most significant distinction lies in whether the library provides the UI or just the logic.
react-table follows a "headless" architecture. It provides hooks (like useTable, useSortBy, usePagination) that manage state and logic but render nothing. You are responsible for writing the <table>, <thead>, <tbody>, and <tr> tags yourself. This offers maximum flexibility but requires more boilerplate code.
// react-table: You define the markup
import { useTable } from 'react-table';
function Table({ columns, data }) {
const {
getTableProps,
getTableBodyProps,
headerGroups,
rows,
prepareRow,
} = useTable({ columns, data });
return (
<table {...getTableProps()}>
<thead>
{headerGroups.map(headerGroup => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map(column => (
<th {...column.getHeaderProps()}>{column.render('Header')}</th>
))}
</tr>
))}
</thead>
<tbody {...getTableBodyProps()}>
{rows.map(row => {
prepareRow(row);
return (
<tr {...row.getRowProps()}>
{row.cells.map(cell => (
<td {...cell.getCellProps()}>{cell.render('Cell')}</td>
))}
</tr>
);
})}
</tbody>
</table>
);
}
mui-datatables is an integrated solution. It is a single component that handles everything: logic, state, and rendering. It is tightly coupled with Material-UI (MUI). You pass data and configuration options, and it renders a fully styled Material Design table.
// mui-datatables: Integrated UI component
import MUIDataTable from "mui-datatables";
function MyTable() {
const columns = ["Name", "Title", "Location"];
const data = [
["Gabby George", "Business Analyst", "Minneapolis"],
["Aiden Lloyd", "Business Consultant", "Dallas"]
];
const options = {
filter: true,
filterType: "dropdown",
responsive: "vertical",
};
return <MUIDataTable title={"Employee List"} data={data} columns={columns} options={options} />;
}
react-data-table-component sits in the middle. It is an integrated component like mui-datatables, but it is not tied to a specific CSS framework. It renders its own internal structure but allows you to inject custom styles via a customStyles prop or standard CSS classes. It provides a rich set of features out of the box without forcing a specific design language.
// react-data-table-component: Standalone integrated component
import DataTable from 'react-data-table-component';
const columns = [
{ name: 'Title', selector: row => row.title, sortable: true },
{ name: 'Director', selector: row => row.director, sortable: true },
];
const MyTable = () => (
<DataTable
title="Movies"
columns={columns}
data={myData}
selectableRows
expandableRows
/>
);
How you style the table is often the deciding factor in library selection.
With react-table, styling is 100% your responsibility. You can use Tailwind CSS, Styled Components, Emotion, or plain CSS modules. There is no default theme to override. This is perfect for custom design systems but requires significant upfront effort.
// react-table: Custom styling via className or style props
<tr {...row.getRowProps()} style={{ background: index % 2 === 0 ? '#f0f0f0' : 'white' }}>
{/* Custom TD rendering */}
</tr>
With mui-datatables, styling is handled by the MUI theme system. You can customize colors, fonts, and spacing by modifying the MUI ThemeProvider. However, breaking out of the Material Design look can be difficult and often requires aggressive CSS overrides.
// mui-datatables: Themed via MUI ThemeProvider
// The table automatically inherits primary/secondary colors from your theme
<ThemeProvider theme={myCustomTheme}>
<MUIDataTable data={data} columns={columns} />
</ThemeProvider>
With react-data-table-component, you get a clean default look that is framework-agnostic. For customization, you pass a customStyles object to target specific elements (head, row, cell) without needing global CSS hacks. This offers a good balance between "it just works" and "I need it to look exactly like my brand."
// react-data-table-component: Programmatic styling
const customStyles = {
headRow: {
style: {
backgroundColor: '#333',
color: '#fff',
},
},
rows: {
style: {
'&:hover': {
backgroundColor: '#f5f5f5',
},
},
},
};
<DataTable customStyles={customStyles} data={data} columns={columns} />
All three libraries support sorting and filtering, but the implementation complexity varies.
In react-table, you must explicitly import and combine plugins. You pass useSortBy and useFilters into the useTable hook. You also have to render the UI for the sort buttons and filter inputs yourself within the header cells.
// react-table: Explicit plugin usage and manual UI
import { useTable, useSortBy, useFilters } from 'react-table';
// Hook combination
const {
getTableProps,
headerGroups,
// ... other props
} = useTable(
{ columns, data },
useFilters,
useSortBy
);
// Manual rendering of sort UI in Header
<th {...column.getHeaderProps(column.getSortByToggleProps())}>
{column.render('Header')}
<span>{column.isSorted ? (column.isSortedDesc ? ' 🔽' : ' 🔼') : ''}</span>
</th>
In mui-datatables, these features are enabled via simple boolean flags in the options object. The library renders the dropdowns, icons, and logic automatically.
// mui-datatables: Configuration driven
const options = {
sort: true,
filter: true,
filterType: 'checkbox', // Built-in filter types
selectableRows: true,
};
// No manual UI rendering required for basic features
In react-data-table-component, features like sorting are enabled via props on the column definition (sortable: true). Filtering often requires a bit more setup than mui-datatables but is still much simpler than react-table. It provides built-in components for pagination and selection.
// react-data-table-component: Column-level configuration
const columns = [
{
name: 'Title',
selector: row => row.title,
sortable: true, // Enables sorting
filterable: true // Enables filtering
}
];
// Pagination and selection are built-in props on the main component
A critical architectural consideration is the long-term viability of the library.
mui-datatables has faced periods of slow maintenance and compatibility issues with newer versions of Material-UI (MUI v5). While it is still widely used, developers should verify current compatibility with the latest MUI version before committing. If your project relies heavily on the latest MUI features, you may encounter friction.
react-data-table-component is actively maintained and has a robust API. It does not depend on a heavy external UI framework, which reduces the risk of breaking changes caused by third-party updates. It is a safe bet for long-term projects that need a stable, feature-rich grid.
react-table (specifically the v8+ version, now often referred to as @tanstack/react-table) is extremely active and considered the industry standard for headless tables. It is highly optimized for performance and tree-shaking. If you are starting a new project and have the resources to build the UI layer, this is the most future-proof choice.
| Feature | react-table | mui-datatables | react-data-table-component |
|---|---|---|---|
| UI Rendering | None (Headless) | Full (Material Design) | Full (Agnostic) |
| Styling Effort | High (Build from scratch) | Low (Theme based) | Medium (Custom styles prop) |
| Setup Complexity | High (Hooks + Markup) | Low (Props only) | Low (Props + Columns) |
| Bundle Size | Minimal (Tree-shakable) | Heavy (MUI Dependent) | Moderate |
| Flexibility | Unlimited | Restricted to MUI | High |
| Best For | Design Systems, Custom UI | Internal Tools, MUI Apps | Rapid Dev, Non-MUI Apps |
If you are building a custom design system or need pixel-perfect control over every DOM element, react-table is the only correct choice. It demands more code but pays off in flexibility and performance.
If your team is already using Material-UI and needs to ship an admin panel quickly, mui-datatables offers the fastest path to completion, provided you verify its compatibility with your specific MUI version.
For most other scenarios—where you need a powerful, feature-rich table (sorting, filtering, pagination, expansion) without the constraints of Material-UI or the boilerplate of a headless library—react-data-table-component strikes the best balance. It allows you to focus on business logic rather than table internals while keeping your styling options open.
Choose mui-datatables if your project is already deeply invested in the Material-UI ecosystem and you need a quick, feature-rich implementation without custom styling efforts. It is ideal for internal admin dashboards or enterprise tools where adhering to Material Design guidelines is a priority and development speed outweighs the need for unique visual branding.
Choose react-data-table-component if you need a powerful, ready-to-use table component but do not want to commit to a specific CSS framework like Material-UI. It is the best fit for projects requiring complex features like expandable rows, context menus, and conditional row styling out of the box, while retaining the freedom to use Tailwind, Styled Components, or plain CSS for the rest of the application.
Choose react-table if you require complete control over the HTML structure and styling of your table, or if you are building a custom design system from scratch. It is the superior choice for high-performance applications where bundle size optimization is critical, as it allows you to only import the specific hooks you need and avoids the overhead of pre-built UI components.
MUI-Datatables is a responsive datatables component built on Material-UI. It comes with features like filtering, resizable columns, view/hide columns, draggable columns, search, export to CSV download, printing, selectable rows, expandable rows, pagination, and sorting. On top of the ability to customize styling on most views, there are three responsive modes "vertical", "standard", and "simple" for mobile/tablet devices.
Version 3 has been released! You can read about the updates here!
npm install mui-datatables --save
If your project doesn't already use them, you need to install mui v5 and it's icon pack:
npm --save install @mui/material @emotion/react @emotion/styled @mui/icons-material
| mui-datatables | material-ui | Required Dependencies |
|---|---|---|
| ^2.0.0 | ^3.0.0 | @material-ui/core,@material-ui/icons |
| ^3.0.0 | ^4.10.0 | @material-ui/core,@material-ui/icons |
| ^3.8.0 | ^4.12.0 | @material-ui/core,@material-ui/icons |
| ^4.0.0 | ^5.9.3 | @mui/material,@mui/icons-material |
Browse live demos of all examples in this repo in here!
For a simple table:
import MUIDataTable from "mui-datatables";
const columns = ["Name", "Company", "City", "State"];
const data = [
["Joe James", "Test Corp", "Yonkers", "NY"],
["John Walsh", "Test Corp", "Hartford", "CT"],
["Bob Herm", "Test Corp", "Tampa", "FL"],
["James Houston", "Test Corp", "Dallas", "TX"],
];
const options = {
filterType: 'checkbox',
};
<MUIDataTable
title={"Employee List"}
data={data}
columns={columns}
options={options}
/>
Or customize columns:
import React from "react"
import MUIDataTable from "mui-datatables";
const columns = [
{
name: "name",
label: "Name",
options: {
filter: true,
sort: true,
}
},
{
name: "company",
label: "Company",
options: {
filter: true,
sort: false,
}
},
{
name: "city",
label: "City",
options: {
filter: true,
sort: false,
}
},
{
name: "state",
label: "State",
options: {
filter: true,
sort: false,
}
},
];
const data = [
{ name: "Joe James", company: "Test Corp", city: "Yonkers", state: "NY" },
{ name: "John Walsh", company: "Test Corp", city: "Hartford", state: "CT" },
{ name: "Bob Herm", company: "Test Corp", city: "Tampa", state: "FL" },
{ name: "James Houston", company: "Test Corp", city: "Dallas", state: "TX" },
];
const options = {
filterType: 'checkbox',
};
<MUIDataTable
title={"Employee List"}
data={data}
columns={columns}
options={options}
/>
The component accepts the following props:
| Name | Type | Description |
|---|---|---|
title | array | Title used to caption table |
columns | array | Columns used to describe table. Must be either an array of simple strings or objects describing a column |
data | array | Data used to describe table. Must be either an array containing objects of key/value pairs with values that are strings or numbers, or arrays of strings or numbers (Ex: data: [{"Name": "Joe", "Job Title": "Plumber", "Age": 30}, {"Name": "Jane", "Job Title": "Electrician", "Age": 45}] or data: [["Joe", "Plumber", 30], ["Jane", "Electrician", 45]]). The customBodyRender and customBodyRenderLite options can be used to control the data display. |
options | object | Options used to describe table |
components | object | Custom components used to render the table |
| Name | Type | Default | Description |
|---|---|---|---|
caseSensitive | boolean | false | Enable/disable case sensitivity for search. |
confirmFilters | boolean | false | Works in conjunction with the customFilterDialogFooter option and makes it so filters have to be confirmed before being applied to the table. When this option is true, the customFilterDialogFooter callback will receive an applyFilters function which, when called, will apply the filters to the table. Example |
columnOrder | array | An array of numbers (column indices) indicating the order the columns should be displayed in. Defaults to the order provided by the Columns prop. This option is useful if you'd like certain columns to swap positions (see draggableColumns option). | |
count | number | User provided override for total number of rows. | |
customFilterDialogFooter | function | Add a custom footer to the filter dialog. customFilterDialogFooter(curentFilterList: array, applyFilters: function) => React Component | |
customFooter | function | Render a custom table footer. function(count, page, rowsPerPage, changeRowsPerPage, changePage, textLabels: object) => string| React Component Example | |
customRowRender | function | Override default row rendering with custom function. customRowRender(data, dataIndex, rowIndex) => React Component | |
customSearch | function | Override default search with custom function. customSearch(searchQuery: string, currentRow: array, columns: array) => boolean | |
customSearchRender | function | Render a custom table search. customSearchRender(searchText: string, handleSearch, hideSearch, options) => React Component | |
customSort | function | Override default sorting with custom function. If you just need to override the sorting for a particular column, see the sortCompare method in the column options. function(data: array, colIndex: number, order: string) => array Example | |
customTableBodyFooterRender | function | Render a footer under the table body but above the table's standard footer. This is useful for creating footers for individual columns. Example | |
customToolbar | function | Render a custom toolbar function({displayData}) => React Component | |
customToolbarSelect | function | Render a custom selected rows toolbar. function(selectedRows, displayData, setSelectedRows) => void | |
download | boolean or string | true | Show/hide download icon from toolbar. Possible values:
|
downloadOptions | object | see -> | An object of options to change the output of the CSV file:
Default Value: |
draggableColumns | object | {} | An object of options describing how dragging columns should work. The options are:
|
elevation | number | 4 | Shadow depth applied to Paper component. |
enableNestedDataAccess | string | "" | If provided a non-empty string (ex: "."), it will use that value in the column's names to access nested data. For example, given a enableNestedDataAccess value of "." and a column name of "phone.cell", the column would use the value found in phone:{cell:"555-5555"}. Any amount of nesting will work. Example demonstrates the functionality. |
expandableRows | boolean | false | Enable/disable expandable rows. Example |
expandableRowsHeader | boolean | true | Show/hide the expand all/collapse all row header for expandable rows. |
expandableRowsOnClick | boolean | false | Enable/disable expand trigger when row is clicked. When False, only expand icon will trigger this action. |
filter | boolean or string | true | Show/hide filter icon from toolbar. Possible values:
|
filterArrayFullMatch | boolean | true | For array values, default checks if all the filter values are included in the array. If false, checks if at least one of the filter values is in the array. |
filterType | string | Choice of filtering view. enum('checkbox', 'dropdown', 'multiselect', 'textField', 'custom') | |
fixedHeader | boolean | true | Enable/disable a fixed header for the table Example |
fixedSelectColumn | boolean | true | Enable/disable fixed select column. Example |
isRowExpandable | function | Enable/disable expansion or collapse on certain expandable rows with custom function. Will be considered true if not provided. function(dataIndex: number, expandedRows: object(lookup: {dataIndex: number}, data: arrayOfObjects: {index: number, dataIndex: number})) => boolean. | |
isRowSelectable | function | Enable/disable selection on certain rows with custom function. Returns true if not provided. function(dataIndex: number, selectedRows: object(lookup: {dataindex: boolean}, data: arrayOfObjects: {index, dataIndex})) => boolean. | |
jumpToPage | boolean | false | When true, this option adds a dropdown to the table's footer that allows a user to navigate to a specific page. Example |
onCellClick | function | Callback function that triggers when a cell is clicked. function(colData: any, cellMeta: { colIndex: number, rowIndex: number, dataIndex: number }) => void | |
onChangePage | function | Callback function that triggers when a page has changed. function(currentPage: number) => void | |
onChangeRowsPerPage | function | Callback function that triggers when the number of rows per page has changed. function(numberOfRows: number) => void | |
onColumnOrderChange | function | Callback function that triggers when a column has been dragged to a new location. function(newColumnOrder:array, columnIndex:number, newPosition:number) => void | |
onColumnSortChange | function | Callback function that triggers when a column has been sorted. function(changedColumn: string, direction: string) => void | |
onDownload | function | A callback function that triggers when the user downloads the CSV file. In the callback, you can control what is written to the CSV file. This method can be used to add the Excel specific BOM character (see this example). function(buildHead: (columns) => string, buildBody: (data) => string, columns, data) => string. Return false to cancel download of file. | |
onFilterChange | function | Callback function that triggers when filters have changed. function(changedColumn: string, filterList: array, type: enum('checkbox', 'dropdown', 'multiselect', 'textField', 'custom', 'chip', 'reset'), changedColumnIndex, displayData) => void | |
onFilterChipClose | function | Callback function that is triggered when a user clicks the "X" on a filter chip. function(index : number, removedFilter : string, filterList : array) => void Example | |
onFilterConfirm | function | Callback function that is triggered when a user presses the "confirm" button on the filter popover. This occurs only if you've set confirmFilters option to true. function(filterList: array) => void Example | |
onFilterDialogClose | function | Callback function that triggers when the filter dialog closes. function() => void | |
onFilterDialogOpen | function | Callback function that triggers when the filter dialog opens. function() => void | |
onRowClick | function | Callback function that triggers when a row is clicked. function(rowData: string[], rowMeta: { dataIndex: number, rowIndex: number }) => void | |
onRowExpansionChange | function | Callback function that triggers when row(s) are expanded/collapsed. function(currentRowsExpanded: array, allRowsExpanded: array, rowsExpanded: array) => void | |
onRowsDelete | function | Callback function that triggers when row(s) are deleted. function(rowsDeleted: object(lookup: {[dataIndex]: boolean}, data: arrayOfObjects: {index: number, dataIndex: number}), newTableData) => void OR false (Returning false prevents row deletion.) | |
onRowSelectionChange | function | Callback function that triggers when row(s) are selected/deselected. function(currentRowsSelected: array, allRowsSelected: array, rowsSelected: array) => void | |
onSearchChange | function | Callback function that triggers when the search text value has changed. function(searchText: string) => void | |
onSearchClose | function | Callback function that triggers when the searchbox closes. function() => void | |
onSearchOpen | function | Callback function that triggers when the searchbox opens. function() => void | |
onTableChange | function | Callback function that triggers when table state has changed. function(action: string, tableState: object) => void | |
onTableInit | function | Callback function that triggers when table state has been initialized. function(action: string, tableState: object) => void | |
onViewColumnsChange | function | Callback function that triggers when a column view has been changed. Previously known as onColumnViewChange. function(changedColumn: string, action: string) => void | |
page | number | User provided page for pagination. | |
pagination | boolean | true | Enable/disable pagination. |
print | boolean or string | true | Show/hide print icon from toolbar. Possible values:
|
renderExpandableRow | function | Render expandable row. function(rowData, rowMeta) => React Component Example | |
resizableColumns | boolean | false | Enable/disable resizable columns. |
responsive | string | 'stacked' | Enable/disable responsive table views. Options:
|
rowHover | boolean | true | Enable/disable hover style over rows. |
rowsExpanded | array | User provided expanded rows. | |
rowsPerPage | number | 10 | Number of rows allowed per page. |
rowsPerPageOptions | array | [10,15,100] | Options to provide in pagination for number of rows a user can select. |
rowsSelected | array | User provided array of numbers (dataIndexes) which indicates the selected rows. | |
search | boolean or string | true | Show/hide search icon from toolbar. Possible values:
|
searchPlaceholder | string | Search text placeholder. Example | |
searchProps | object | {} | Props applied to the search text box. You can set method callbacks like onBlur, onKeyUp, etc, this way. Example |
searchOpen | boolean | false | Initially displays search bar. |
searchAlwaysOpen | boolean | false | Always displays search bar, and hides search icon in toolbar. |
searchText | string | Search text for the table. | |
selectableRows | string | 'multiple' | Indicates if rows can be selected. Options are "multiple", "single", "none". |
selectableRowsHeader | boolean | true | Show/hide the select all/deselect all checkbox header for selectable rows. |
selectableRowsHideCheckboxes | boolean | false | Hides the checkboxes that appear when selectableRows is set to "multiple" or "single". Can provide a more custom UX, especially when paired with selectableRowsOnClick. |
selectableRowsOnClick | boolean | false | Enable/disable select toggle when row is clicked. When False, only checkbox will trigger this action. |
selectToolbarPlacement | string | 'replace' | Controls the visibility of the Select Toolbar, options are 'replace' (select toolbar replaces default toolbar when a row is selected), 'above' (select toolbar will appear above default toolbar when a row is selected) and 'none' (select toolbar will never appear) |
serverSide | boolean | false | Enable remote data source. |
setFilterChipProps | function | Is called for each filter chip and allows you to place custom props on a filter chip. function(colIndex: number, colName: string, filterValue: string) => object Example | |
setRowProps | function | Is called for each row and allows you to return custom props for this row based on its data. function(row: array, dataIndex: number, rowIndex: number) => object Example | |
setTableProps | function | Is called for the table and allows you to return custom props for the table based on its data. function() => object Example | |
sort | boolean | true | Enable/disable sort on all columns. |
sortFilterList | boolean | true | Enable/disable alphanumeric sorting of filter lists. |
sortOrder | object | {} | Sets the column to sort by and its sort direction. To remove/reset sorting, input in an empty object. The object options are the column name and the direction: name: string, direction: enum('asc', 'desc') Example |
tableId | string | auto generated | A string that is used internally for identifying the table. It's auto-generated, however, if you need it set to a custom value (ex: server-side rendering), you can set it via this property. |
tableBodyHeight | string | 'auto' | CSS string for the height of the table (ex: '500px', '100%', 'auto'). |
tableBodyMaxHeight | string | CSS string for the height of the table (ex: '500px', '100%', 'auto'). | |
textLabels | object | User provided labels to localize text. | |
viewColumns | boolean or string | true | Show/hide viewColumns icon from toolbar. Possible values:
|
storageKey | string | save current state to local storage(Only browser). |
On each column object, you have the ability to customize columns to your liking with the 'options' property. Example:
const columns = [
{
name: "Name",
options: {
filter: true,
sort: false
}
},
...
];
| Name | Type | Description |
|---|---|---|
name | string | Name of column (This field is required) |
label | string | Column Header Name override |
options | object | Options for customizing column |
| Name | Type | Default | Description |
|---|---|---|---|
customBodyRender | function | Function that returns a string or React component. Used to display data within all table cells of a given column. The value returned from this function will be used for filtering in the filter dialog. If this isn't need, you may want to consider customBodyRenderLite instead. function(value, tableMeta, updateValue) => string| React Component Example | |
customBodyRenderLite | function | Function that returns a string or React component. Used to display data within all table cells of a given column. This method performs better than customBodyRender but has the following caveats:
function(dataIndex, rowIndex) => string| React Component Example | |
customHeadLabelRender | function | Function that returns a string or React component. Used for creating a custom header to a column. This method only affects the display in the table's header, other areas of the table (such as the View Columns popover), will use the column's label. function(columnMeta : object) => string| React Component | |
customFilterListOptions | object | (These options only affect the filter chips that display after filters are selected. To modify the filters themselves, see filterOptions)
| |
customHeadRender | function | Function that returns a string or React component. Used as display for column header. function(columnMeta, handleToggleColumn, sortOrder) => string| React Component | |
display | boolean or string | true | Display column in table. Possible values:
See also: |
download | boolean | true | Display column in CSV download file. |
draggable | boolean | true | Determines if a column can be dragged. The draggableColumns.enabled option must also be true. |
empty | boolean | false | This denotes whether the column has data or not (for use with intentionally empty columns). |
filter | boolean | true | Display column in filter list. |
filterList | array | Filter value list Example | |
filterOptions | object | These options affect the filter display and functionality from the filter dialog. To modify the filter chips that display after selecting filters, see This option is an object of several options for customizing the filter display and how filtering works.
| |
filterType | string | 'dropdown' | Choice of filtering view. Takes priority over global filterType option.enum('checkbox', 'dropdown', 'multiselect', 'textField', 'custom') Use 'custom' if you are supplying your own rendering via filterOptions. |
hint | string | Display hint icon with string as tooltip on hover. | |
print | boolean | true | Display column when printing. |
searchable | boolean | true | Exclude/include column from search results. |
setCellHeaderProps | function | Is called for each header cell and allows you to return custom props for the header cell based on its data. function(columnMeta: object) => object Example | |
setCellProps | function | Is called for each cell and allows to you return custom props for this cell based on its data. function(cellValue: string, rowIndex: number, columnIndex: number) => object Example | |
sort | boolean | true | Enable/disable sorting on column. |
sortCompare | function | Custom sort function for the column. Takes in an order string and returns a function that compares the two column values. If this method and options.customSort are both defined, this method will take precedence. (order) => ({data: val1}, {data: val2}) => number Example | |
sortDescFirst | boolean | false | Causes the first click on a column to sort by desc rather than asc. Example |
sortThirdClickReset | boolean | false | Allows for a third click on a column header to undo any sorting on the column. Example |
viewColumns | boolean | true | Allow user to toggle column visibility through 'View Column' list. |
customHeadRender is called with these arguments:
function(columnMeta: {
customHeadRender: func,
display: enum('true', 'false', 'excluded'),
filter: boolean,
sort: boolean,
download: boolean,
empty: boolean,
index: number,
label: string,
name: string,
print: boolean,
searchable: boolean,
viewColumns: boolean
}, handleToggleColumn: function(columnIndex))
customBodyRender is called with these arguments:
function(value: any, tableMeta: {
rowIndex: number,
columnIndex: number,
columnData: array, // Columns Options object
rowData: array, // Full row data
tableData: array, // Full table data - Please use currentTableData instead
currentTableData: array, // The current table data
tableState: {
announceText: null|string,
page: number,
rowsPerPage: number,
filterList: array,
selectedRows: {
data: array,
lookup: object,
},
showResponsive: boolean,
searchText: null|string,
},
}, updateValue: function)
The table lends itself to plug-ins in many areas, especially in the customRender functions. Many use cases for these render functions are common, so a set of plug-ins are available that you can use.
| Name | Type | Default | Description |
|---|---|---|---|
debounceSearchRender | function | Function that returns a function for the customSearchRender method. This plug-in allows you to create a debounced search which can be useful for server-side tables and tables with large data sets. function(debounceWait) => function Example |
Using Material-UI theme overrides will allow you to customize styling to your liking. First, determine which component you would want to target and then lookup the override classname. Let's start with a simple example where we will change the background color of a body cell to be red:
import React from "react";
import MUIDataTable from "mui-datatables";
import { createTheme, ThemeProvider } from '@mui/material/styles';
class BodyCellExample extends React.Component {
getMuiTheme = () => createTheme({
components: {
MUIDataTableBodyCell: {
styleOverrides:{
root: {
backgroundColor: "#FF0000"
}
}
}
}
})
render() {
return (
<ThemeProvider theme={this.getMuiTheme()}>
<MUIDataTable title={"ACME Employee list"} data={data} columns={columns} options={options} />
</ThemeProvider>
);
}
}
You can pass custom components to further customize the table:
import React from "react";
import Chip from '@mui/material/Chip';
import MUIDataTable, { TableFilterList } from "mui-datatables";
const CustomChip = ({ label, onDelete }) => {
return (
<Chip
variant="outlined"
color="secondary"
label={label}
onDelete={onDelete}
/>
);
};
const CustomFilterList = (props) => {
return <TableFilterList {...props} ItemComponent={CustomChip} />;
};
class CustomDataTable extends React.Component {
render() {
return (
<MUIDataTable
columns={columns}
data={data}
components={{
TableFilterList: CustomFilterList,
}}
/>
);
}
}
Supported customizable components:
Checkbox - A special 'data-description' prop lets you differentiate checkboxes Example. Valid values: ['row-select', 'row-select-header', 'table-filter', 'table-view-col'].The dataIndex is also passed via the "data-index" prop.ExpandButton ExampleDragDropBackendTableBodyTableViewCol - The component that displays the view/hide list of columns on the toolbar.TableFilterList - You can pass ItemComponent prop to render custom filter list item.TableFooterTableHeadTableResizeTableToolbarTableToolbarSelectTooltipicons - An object containing optional replacement icon classes for the actions
toolbar. Example
SearchIconDownloadIconPrintIconViewColumnIconFilterIconFor more information, please see this example. Additionally, all examples can be viewed live at our CodeSandbox.
If you are looking to work with remote data sets or handle pagination, filtering, and sorting on a remote server you can do that with the following options:
const options = {
serverSide: true,
onTableChange: (action, tableState) => {
this.xhrRequest('my.api.com/tableData', result => {
this.setState({ data: result });
});
}
};
To see an example Click Here
This package decided that the cost of bringing in another library to perform localizations would be too expensive. Instead the ability to override all text labels (which aren't many) is offered through the options property textLabels. The available strings:
const options = {
...
textLabels: {
body: {
noMatch: "Sorry, no matching records found",
toolTip: "Sort",
columnHeaderTooltip: column => `Sort for ${column.label}`
},
pagination: {
next: "Next Page",
previous: "Previous Page",
rowsPerPage: "Rows per page:",
displayRows: "of",
},
toolbar: {
search: "Search",
downloadCsv: "Download CSV",
print: "Print",
viewColumns: "View Columns",
filterTable: "Filter Table",
},
filter: {
all: "All",
title: "FILTERS",
reset: "RESET",
},
viewColumns: {
title: "Show Columns",
titleAria: "Show/Hide Table Columns",
},
selectedRows: {
text: "row(s) selected",
delete: "Delete",
deleteAria: "Delete Selected Rows",
},
}
...
}
Thanks for taking an interest in the library and the github community!
The following commands should get you started:
npm i
npm run dev
open http://localhost:5050/ in browser
After you make your changes locally, you can run the test suite with npm test.
The files included in this repository are licensed under the MIT license.
Thank you to BrowserStack for providing the infrastructure that allows us to test in real browsers.