Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override the sort icon on columns #1411

Closed
Eithcowich opened this issue Jul 14, 2020 · 10 comments
Closed

Override the sort icon on columns #1411

Eithcowich opened this issue Jul 14, 2020 · 10 comments

Comments

@Eithcowich
Copy link

The table columns display a 'Sort' tooltip. In many cases overriding it with an explanation of what the column data means is crucial. Is there a way to do it?

@patorjk
Copy link
Collaborator

patorjk commented Jul 14, 2020

Yes, see columnHeaderTooltip in the textLabels option:

https://github.com/gregnb/mui-datatables#localization

@Eithcowich
Copy link
Author

How do I call this for an individual column? I need different tooltips to many of them, so I can explain what's the meaning of the data.

@patorjk
Copy link
Collaborator

patorjk commented Jul 21, 2020

The function gives you the column object, so you can change the tooltip based on what the column is. Example:

columnHeaderTooltip: column => {
    if (column.name === 'type') return 'Type!';
    return `Sort for ${column.label}`;
}

@Eithcowich
Copy link
Author

I can successfully change the toolTip or the noMatch but I'm not seeing this function getting called:

       columnHeaderTooltip : (column) => {
              console.log('column ' + column);
              if (column.name === 'daoPlatform') return 'This is the DAO platform';
              return ( <span>{column.label}</span> )
       },

and the sorting tooltip doesn't change.

I'm on version 2.6.4. I tried 3.2 but too many things changed and we're in a tight production deadline right now so I cannot upgrade yet.

@patorjk
Copy link
Collaborator

patorjk commented Jul 22, 2020

I would recommending upgrading. 3.x really doesn't require much other than Material UI v4 (most of the deprecation notices are optional).

Unfortunately the pervious maintainer did not mention columnHeaderTooltip in the release notes, so it's unclear when that got added in. You try upgrading to v2.14.0 (this was the last verison done by the previous maintainer). That version would probably have less updates that you would have to do. However, I wouldn't be able to help you if you ran into any issues.

@Eithcowich
Copy link
Author

OK, I'll try that.

Re V3, the sorting order seems broken. When I set it for the whole table as desc it works for the initial column, but then every click sorts the table on the relevant column asc. I tried playing with it a bit and see if I can change it in the customSort function but couldn't really spend the time and went back to my previous version.

@patorjk
Copy link
Collaborator

patorjk commented Jul 22, 2020

It’s not broken. Someone noted that the standard way of sorting a table was to first do asc and then on second click do desc, so the behavior was changed for v3.

@Eithcowich
Copy link
Author

OH I see, cool. It depends on the use case I think. If you're ranking items like we do in https://DeepDAO.io (see your excellent widget in action!) then you always want the desc sorting to be first. But I guess there are other use cases.

@patorjk
Copy link
Collaborator

patorjk commented Jul 24, 2020

I could put in an orderSequence option (similar to: https://datatables.net/examples/advanced_init/sort_direction_control.html), that way the sort sequence could be controlled.

@patorjk
Copy link
Collaborator

patorjk commented Jul 25, 2020

I added a new option called sortDescFirst in 3.3.0 that will columns to sort by desc first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants