MRT logoMaterial React Table

    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

    1
    Partial<MRT_Icons>;

    No Description Provided... Yet...

    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.

    <MaterialTable
    columns={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.


    Demo

    Open Code SandboxOpen on GitHub
    DylanMurray261 Erdman FordEast DaphneKentucky
    RaquelKohler769 Dominic GroveColumbusOhio
    ErvinReinger566 Brakus InletSouth LindaWest Virginia
    BrittanyMcCullough722 Emie StreamLincolnNebraska
    BransonFrami32188 Larkin TurnpikeCharlestonSouth Carolina

    Rows per page

    1-5 of 5

    Source Code

    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;
    28
    29/**
    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 applied
    52 ),
    53 PushPinIcon: (props: any) => (
    54 <FontAwesomeIcon icon={faThumbTack} {...props} /> //props so that style rotation transforms are applied
    55 ),
    56 VisibilityOffIcon: () => <FontAwesomeIcon icon={faEyeSlash} />,
    57};
    58
    59const Example: FC = () => {
    60 const columns = useMemo(
    61 //column definitions...
    88 );
    89
    90 return (
    91 <MaterialReactTable
    92 columns={columns}
    93 data={data}
    94 enableColumnOrdering
    95 enablePinning
    96 icons={fontAwesomeIcons}
    97 />
    98 );
    99};
    100
    101export default Example;
    102