Customizing Icons Feature Guide
Material React Table uses Material Icons by default for all of its internal icons.
If you need to, you can customize and replace some or all of the icons with your own custom icons. You can either use other Material Icons, or icons from a completely different library.
Relevant Props
Replace with Custom Icons
To replace a default icon, you specify the icon in the icons
prop. You should get TS hints for the name of the icons you can replace, but you can also consult this source file for a list of all the icons you can replace.
<MaterialTablecolumns={columns}data={data}icons={{SearchIcon: () => <FontAwesomeIcon icon={faSearch} />,SortIcon: (props) => (<FontAwesomeIcon icon={faArrowDownWideShort} {...props} />), //best practice}}
Some Icons have
style
props that get applied to them internally. So in order to preserve the ability of those Icons to be styled with the correct paddings, margins, or rotations, you should pass in{...props}
to your custom Icon component as a best practice.
Font Awesome Example
Here is an example where we use icons from a completely different library, Font Awesome.
First Name | Last Name | Address | City | State |
---|---|---|---|---|
Dylan | Murray | 261 Erdman Ford | East Daphne | Kentucky |
Raquel | Kohler | 769 Dominic Grove | Columbus | Ohio |
Ervin | Reinger | 566 Brakus Inlet | South Linda | West Virginia |
Brittany | McCullough | 722 Emie Stream | Lincoln | Nebraska |
Branson | Frami | 32188 Larkin Turnpike | Charleston | South Carolina |
1import React, { FC, useMemo } from 'react';2import MaterialReactTable, {3 MRT_ColumnDef,4 MRT_Icons,5} from 'material-react-table';6import { data, Person } from './makeData';7import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';8import {9 faArrowDownWideShort,10 faBars,11 faBarsStaggered,12 faColumns,13 faCompress,14 faEllipsisH,15 faEllipsisVertical,16 faExpand,17 faEyeSlash,18 faFilter,19 faFilterCircleXmark,20 faGripLines,21 faSearch,22 faSearchMinus,23 faThumbTack,24} from '@fortawesome/free-solid-svg-icons';25import '@fortawesome/fontawesome-svg-core/styles.css';26import { config } from '@fortawesome/fontawesome-svg-core';27config.autoAddCss = false;2829/**30 * These are just some of the icons visible in this table's feature set.31 * If you skip customizing some icons, those particular icons will fallback the the default Material-UI icons.32 */33const fontAwesomeIcons: Partial<MRT_Icons> = {34 ClearAllIcon: () => <FontAwesomeIcon icon={faBarsStaggered} />,35 DensityLargeIcon: () => <FontAwesomeIcon icon={faGripLines} />,36 DensityMediumIcon: () => <FontAwesomeIcon icon={faBars} />,37 DensitySmallIcon: () => <FontAwesomeIcon icon={faBars} />,38 DragHandleIcon: () => <FontAwesomeIcon icon={faGripLines} />,39 FilterListIcon: (props: any) => (40 <FontAwesomeIcon icon={faFilter} {...props} />41 ),42 FilterListOffIcon: () => <FontAwesomeIcon icon={faFilterCircleXmark} />,43 FullscreenExitIcon: () => <FontAwesomeIcon icon={faCompress} />,44 FullscreenIcon: () => <FontAwesomeIcon icon={faExpand} />,45 SearchIcon: (props: any) => <FontAwesomeIcon icon={faSearch} {...props} />,46 SearchOffIcon: () => <FontAwesomeIcon icon={faSearchMinus} />,47 ViewColumnIcon: () => <FontAwesomeIcon icon={faColumns} />,48 MoreVertIcon: () => <FontAwesomeIcon icon={faEllipsisVertical} />,49 MoreHorizIcon: () => <FontAwesomeIcon icon={faEllipsisH} />,50 SortIcon: (props: any) => (51 <FontAwesomeIcon icon={faArrowDownWideShort} {...props} /> //props so that style rotation transforms are applied52 ),53 PushPinIcon: (props: any) => (54 <FontAwesomeIcon icon={faThumbTack} {...props} /> //props so that style rotation transforms are applied55 ),56 VisibilityOffIcon: () => <FontAwesomeIcon icon={faEyeSlash} />,57};5859const Example: FC = () => {60 const columns = useMemo(61 //column definitions...88 );8990 return (91 <MaterialReactTable92 columns={columns}93 data={data}94 enableColumnOrdering95 enablePinning96 icons={fontAwesomeIcons}97 />98 );99};100101export default Example;102