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.

Localization or custom label for PaginationItem

See original GitHub issue

PaginationItem should allow users to add custom text in pagination button so that they could customize or localize it.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

Pagination component gives you renderItem props which can be used to customize how pagination items are rendered. In order to use renderItem you can provide a PaginationItem with your own customization for instance you can make it as react-router-dom Link. However, I was not able to give PaginationItem a custom text for localization. There are two ways that I can achieve custom text for pagination which honestly is just too much work for just a localized number in pagination. The first one is to use usePagination and the other option is to implement a new PaginationItem with localized texts. I think it would be a good idea to have a prop on PaginationItem for custom text.

PaginationItem should have an optional prop for showing a custom text in pagination buttons. I have noticed that there is title prop which only add a tool-tip for accessibility. the implementation would be like this:

<ButtonBase
      ref={ref}
      component={component}
      disabled={disabled}
      focusVisibleClassName={classes.focusVisible}
      className={clsx(
        classes.root,
        classes.page,
        classes[variant],
        classes[shape],
        {
          [classes[`${variant}${capitalize(color)}`]]: color !== 'standard',
          [classes.disabled]: disabled,
          [classes.selected]: selected,
          [classes[`size${capitalize(size)}`]]: size !== 'medium',
        },
        className,
      )}
      {...other}
    >
      // check if label prop is available show it instead of page
      {type === 'page' && !label && page}
      {type === 'page' && !!label && label}
      {Icon ? <Icon className={classes.icon} /> : null}
    </ButtonBase>

Examples 🌈

<Pagination
  page={page}
  count={10}
  renderItem={(item) => (
    <PaginationItem
      component={Link}
      to={`/inbox${item.page === 1 ? "" : `?page=${item.page}`}`}
      // localized number or a custom text as label
      label={t("number", { number: item.page })}
      {...item}
    />
  )}
/>

Motivation 🔦

This helps to localize pagination without implementing extra component

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mnajdovacommented, May 14, 2021

Perfect, thanks @mohammadalijf

1reaction
mohammadalijfcommented, May 14, 2021

@mnajdova Sorry for inconvenience… documentation link for source code was pointing to a commit were it was outdated. On next branch where Pagination is moved to core, it has already been fixed. I searched Issues but I couldn’t find a related issue. In 91f2bb22dee473e9dbbb90a84a5d9bc898f7d760 page type is changed from number to React.ReactNode which will resolve the issue. Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Define Localized Component Labels and Attribute Values on ...
With Localization Support in App Builder, when you specify a custom label in the Lightning App Builder, you can use {!$Label.customLabelName} to help...
Read more >
Material UI -Data Grid Custom Pagination - Stack Overflow
I am trying to use the custom pagination from here https://material-ui.com/components/data-grid/style/#custom-theme.
Read more >
TablePagination API - Material UI - MUI
Customize the displayed rows label. Invoked with a { from, to, count, page } object. For localization purposes, you can use the provided...
Read more >
Pagination | Calcite Design System - ArcGIS Developers
A custom string. "Next" (default). textLabelPrevious, text-label-previous. Accessible name for the component's previous button.
Read more >
Database: Pagination - The PHP Framework For Web Artisans
The cursor is an encoded string containing the location that the next paginated query should start paginating and the direction that it should...
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