question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Column CustomHeadRender reuse the sortToggle function

See original GitHub issue

Column 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:open
  • Created 5 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

1reaction
dandreicommented, Sep 11, 2019

A quick heads up for this thread: a recent update in mui-datatables changed the default value of an unsorted sortDirection to "none" (as opposed to null).

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:

<TableSortLabel active={column.sortDirection !== "none"} ... />
1reaction
pcrane-zagcommented, Jul 30, 2019

I would find this useful as well; for a tooltip I can use hint but I’d like to just override the basic Sort tooltip and skip the icon without re-implementing the rest of the header.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found