Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default sorting icon on table header column on React Material-Table?

Can I change the default sorting icon on React Material-Table table header column ? ex. I want to change asc sorting icon to ArrowDownward and desc sorting icon to ArrowUpward. I try to set SortArrow icons props on MaterialTable but its show on every table header columns even its not active sorting column. Please help.

Material-Table

Code:

<MaterialTable ... icons={{ SortArrow: () => <ArrowDownwardIcon /> }}
like image 734
Mashizilla Avatar asked Oct 17 '25 11:10

Mashizilla


1 Answers

You have to forward the refs like this:

import React, { forwardRef } from 'react';  
...
<MaterialTable>  
     icons={{ SortArrow: forwardRef((props, ref) => <ArrowDownwardIcon{...props} ref={ref}/>)}}
<MaterialTable> 

This will pass the required props to your custom icon and it will work.

like image 188
Domino987 Avatar answered Oct 19 '25 02:10

Domino987



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!