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

[data grid] Format row count numbers in pagination #13222

Open
Tracked by #9328
Janpot opened this issue May 23, 2024 · 13 comments
Open
Tracked by #9328

[data grid] Format row count numbers in pagination #13222

Janpot opened this issue May 23, 2024 · 13 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature feature: Pagination Related to the data grid Pagination feature i18n internationalization l10n localization

Comments

@Janpot
Copy link
Member

Janpot commented May 23, 2024

Summary

Live demo https://stackblitz.com/edit/react-jxqb4n?file=Demo.tsx

The pagination control looks like:

Screenshot 2024-05-23 at 14 58 46

Would it be possible to format these numbers? A thousands separator would make them more readable. In practice this is mostly going to be interesting for the total count, but once you start formatting, you may as well do it for all of these numbers.

Examples

Screenshot 2024-05-23 at 15 05 47

Motivation

No response

Search keywords: pagination format number

@Janpot Janpot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 23, 2024
@Janpot Janpot changed the title [DataGrid] Format row count numbers in pagination [data grid] Format row count numbers in pagination May 23, 2024
@michelengelen
Copy link
Member

Probably already possible with a custom pagination and the TablePagination component ... the prop labelDisplayedRows looks like it would do the trick here

But this seems like a very heavy customization for such a little thing!

@mui/xgrid WDYT?

@michelengelen michelengelen added component: data grid This is the name of the generic UI component, not the React module! feature: Pagination Related to the data grid Pagination feature enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 23, 2024
@flaviendelangle
Copy link
Member

Looking at the code, it seems that you have a labelDisplayedRows locale key on the MuiTablePagination locale entry of the grid (those nested locale entry are super hard to understand IMHO).

This would be nice to have an example if it does work
And if it doesn't and you do need to create a custom pagination component, then I fully agree that we could improve the DX 👍

@michelengelen
Copy link
Member

Oh yes, that actually works!

Screenshot 2024-05-23 at 16 36 50

FYI: numbers were artificially created to test this ((10000).toLocaleString('en'))

Thanks @flaviendelangle for this tip! 👍🏼

slotProps={{
  pagination: { labelDisplayedRows: ({ from, to, count }) => `${from.toLocaleString('en')}-${to.toLocaleString('en')}`},
}}

Copy link

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@Janpot: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

@flaviendelangle
Copy link
Member

@michelengelen do you think it would justify a doc example?

@michelengelen
Copy link
Member

@michelengelen do you think it would justify a doc example?

Probably ... its not easy to find that feature otherwise

I'll reopen and add it to the recipe umbrella!

@flaviendelangle
Copy link
Member

its not easy to find that feature otherwise

It would be nice to have some kind of API pages for the slots, but that's a big initiative and not specific to this prop in particular.

@Janpot
Copy link
Member Author

Janpot commented May 24, 2024

Respecting the decision ofcourse but gonna play a bit advocate of the devil here. To me it seems strange that the localeText is not formatting the numbers it interpollates by default. Imagining there was a text with a date, we wouldn't just stringify that date neither, we'd format it to the user locale. It feels a bit like this API is only doing half its job this way. I find it hard to imagine that not formatting the numbers would be part of more than 5% of use-cases out there.

@flaviendelangle
Copy link
Member

Related issues #7457

@Janpot
Copy link
Member Author

Janpot commented May 24, 2024

Right, SSR, good concern 👍

@flaviendelangle
Copy link
Member

Yeah, I forget that one every time 😆
The Base UI team is experiencing similar issues with the NumberInput, maybe we will be able to use the same approach in the end.

@Janpot
Copy link
Member Author

Janpot commented May 24, 2024

🤔 Actually, if the texts are already localized, why can't the localization of the numbers follow the text? If there is an actual SSR problem, shouldn't it then be already present in the current localization of the texts?

@oliviertassinari
Copy link
Member

oliviertassinari commented May 25, 2024

This looks like a sub-issue of the parent one: mui/material-ui#24495. I proposed a possible solution a while back: mui/material-ui#24495 (comment).


Side observations:

  1. all our locales number formatting feels straight wrong:

`${visibleCount.toLocaleString()} sur ${totalCount.toLocaleString()}`,

I would expect:

 `${visibleCount.toLocaleString('fr-FR')} sur ${totalCount.toLocaleString('fr-FR')}`, 

e.g. if Pennylane adopts our data grid, it will be wrong. My default OS language is English (so what toLocaleString will output), but I might set the language picker in their UI to French so I can take screenshots for the accountant. The data grid would show the number assuming the English locale, not the French one ❌.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature feature: Pagination Related to the data grid Pagination feature i18n internationalization l10n localization
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

4 participants