Column CustomHeadRender reuse the sortToggle function
See original GitHub issueColumn CustomHeadRender rehuse the sort function
Right now I want to create a custom head and use the sort function provided by the table.
Current Behavior
right now is not possible,
Proposal
I noticed the sort function is passed on the customHeadRender function so I made a few changes on the MUIDataTableHead component
line 55
column.customHeadRender({ index, ...column }, (columnIndex) => this.handleToggleColumn(columnIndex))
This give us the oportunity of continue using the sortToggle using the current index or other column index. 😃 I changed the name to columnIndex because the name index is shared inside of the map function on columns array.
const columns = ["Name", "Title", "Location", "Age", {
name: "Salary",
sortDirection: 'asc',
options: {
customHeadRender: ({index, ...column}, sortColumn) => {
return (
<TableCell onClick={() => sortColumn(index)} key={index}>
{column.name}
</TableCell>
);
}
}
}];
I can create the PR to include this small functionality.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:8
Top Results From Across the Web
How to add class on MUI datatable head and respective td for ...
customBodyRender will allow you to customize all rows in a column, but you'll need customHeadRender to customize the header for that column.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A quick heads up for this thread: a recent update in
mui-datatables
changed the default value of an unsortedsortDirection
to"none"
(as opposed tonull
).Anyone who used the above example to build their own custom TH renderer, if upgrading to versions higher than
2.10.3
(when I noticed it, but may be in an earlier build as well) should update the code accordingly:I would find this useful as well; for a tooltip I can use
hint
but I’d like to just override the basicSort
tooltip and skip the icon without re-implementing the rest of the header.