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, 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={{//change sort icon, connect internal props so that it gets styled correctlyArrowDownwardIcon: (props) => <FontAwesomeIcon icon={faSortDown} {...props} />,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 faSortDown,24 faThumbTack,25} from '@fortawesome/free-solid-svg-icons';26import '@fortawesome/fontawesome-svg-core/styles.css';27import { config } from '@fortawesome/fontawesome-svg-core';28config.autoAddCss = false;2930/**31 * These are just some of the icons visible in this table's feature set.32 * If you skip customizing some icons, those particular icons will fallback the the default Material-UI icons.33 */34const fontAwesomeIcons: Partial<MRT_Icons> = {35 ArrowDownwardIcon: (props: any) => <FontAwesomeIcon icon={faSortDown} {...props} />,36 ClearAllIcon: () => <FontAwesomeIcon icon={faBarsStaggered} />,37 DensityLargeIcon: () => <FontAwesomeIcon icon={faGripLines} />,38 DensityMediumIcon: () => <FontAwesomeIcon icon={faBars} />,39 DensitySmallIcon: () => <FontAwesomeIcon icon={faBars} />,40 DragHandleIcon: () => <FontAwesomeIcon icon={faGripLines} />,41 FilterListIcon: (props: any) => (42 <FontAwesomeIcon icon={faFilter} {...props} />43 ),44 FilterListOffIcon: () => <FontAwesomeIcon icon={faFilterCircleXmark} />,45 FullscreenExitIcon: () => <FontAwesomeIcon icon={faCompress} />,46 FullscreenIcon: () => <FontAwesomeIcon icon={faExpand} />,47 SearchIcon: (props: any) => <FontAwesomeIcon icon={faSearch} {...props} />,48 SearchOffIcon: () => <FontAwesomeIcon icon={faSearchMinus} />,49 ViewColumnIcon: () => <FontAwesomeIcon icon={faColumns} />,50 MoreVertIcon: () => <FontAwesomeIcon icon={faEllipsisVertical} />,51 MoreHorizIcon: () => <FontAwesomeIcon icon={faEllipsisH} />,52 SortIcon: (props: any) => (53 <FontAwesomeIcon icon={faArrowDownWideShort} {...props} /> //props so that style rotation transforms are applied54 ),55 PushPinIcon: (props: any) => (56 <FontAwesomeIcon icon={faThumbTack} {...props} /> //props so that style rotation transforms are applied57 ),58 VisibilityOffIcon: () => <FontAwesomeIcon icon={faEyeSlash} />,59};6061const Example: FC = () => {62 const columns = useMemo(63 //column definitions...90 );9192 return (93 <MaterialReactTable94 columns={columns}95 data={data}96 enableColumnOrdering97 enablePinning98 icons={fontAwesomeIcons}99 />100 );101};102103export default Example;104