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

feat: add page start end total to PagerRenderer #9371

Conversation

murilohpucci
Copy link

@murilohpucci murilohpucci commented Jan 4, 2025

Description

I've recently started using CodeIgniter. While working with the pagination library, I noticed that it lacks functionality to easily display the range of results currently being shown alongside the total number of results(unless there's an easy way to get all the information and I wasn't able to figure it out, in this case sorry for all the noise here). This feature is particularly useful when building UI components like the one below:

image

Currently, the PageRenderer.php class (referenced here) gets the total number of results but does not provide a getter to access this information.

This enhancement would be especially beneficial for content editors who rely on result counts to manage their workflows.

Proposed solution
I've created some new variables to hold the information of the items that are showing on the page, and on the construct method if the total items is passed, I call a new function to calculate the items the page started and ended. Then the getters to expose the data.

Disclaimer
This is my first contribution to the project, so I may have missed something or not followed best practices. If so, please let me know.

Regarding documentation updates, I plan to address them in a separate commit once the core functionality is reviewed.
Feel free to review the code! Thanks!

@murilohpucci murilohpucci changed the title Feat - add page start end total to page renderer feat: add page start end total to page renderer Jan 4, 2025
Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks useful, thanks!

system/Pager/PagerRenderer.php Outdated Show resolved Hide resolved
system/Pager/PagerRenderer.php Outdated Show resolved Hide resolved
system/Pager/PagerRenderer.php Outdated Show resolved Hide resolved
@michalsn michalsn added docs needed Pull requests needing documentation write-ups and/or revisions. 4.6 enhancement PRs that improve existing functionalities GPG-Signing needed Pull requests that need GPG-Signing labels Jan 4, 2025
@murilohpucci murilohpucci force-pushed the feature-add-page-start-end-total-to-page-renderer branch from 4147d9f to 2bcf4ab Compare January 4, 2025 16:07
@murilohpucci
Copy link
Author

Thanks for your help @michalsn! Just signed my commits and resolved the type hints. Let's see if anyone else has anything to say about the implementation. Meanwhile I'm gonna write the documentation.

@michalsn michalsn removed the GPG-Signing needed Pull requests that need GPG-Signing label Jan 4, 2025
@neznaika0
Copy link
Contributor

It's been a long time, but this feature has already been requested:
https://forum.codeigniter.com/showthread.php?tid=88174

@murilohpucci
Copy link
Author

Just applied all the suggestion made and thanks for the pointing out the forum post @neznaika0!

system/Pager/PagerRenderer.php Outdated Show resolved Hide resolved
system/Pager/PagerRenderer.php Outdated Show resolved Hide resolved
system/Pager/PagerRenderer.php Outdated Show resolved Hide resolved
system/Pager/PagerRenderer.php Outdated Show resolved Hide resolved
@murilohpucci
Copy link
Author

Your suggentions make sense @neznaika0, thanks! Regarding the documentation, I've added a simple one, it would be nice to a have a review there too. Here's a screenshot to make thinks easier:
image

@neznaika0
Copy link
Contributor

Add note in changelog 4.6

@michalsn
Copy link
Member

michalsn commented Jan 6, 2025

The errors are not related to this PR and they were already fixed in the upstream. Please rebase: https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/workflow.md#updating-your-branch

@michalsn michalsn removed the docs needed Pull requests needing documentation write-ups and/or revisions. label Jan 6, 2025
@murilohpucci murilohpucci force-pushed the feature-add-page-start-end-total-to-page-renderer branch from 8898145 to ce162e2 Compare January 6, 2025 11:44
@murilohpucci
Copy link
Author

Just rebased and added a changelog, thanks for your help @michalsn and @neznaika0!

system/Pager/PagerRenderer.php Outdated Show resolved Hide resolved
tests/system/Pager/PagerRendererTest.php Outdated Show resolved Hide resolved
user_guide_src/source/changelogs/v4.6.0.rst Outdated Show resolved Hide resolved
@paulbalandan paulbalandan changed the title feat: add page start end total to page renderer feat: add page start end total to PagerRenderer Jan 7, 2025
@paulbalandan paulbalandan merged commit d9aca42 into codeigniter4:4.6 Jan 7, 2025
50 checks passed
@paulbalandan
Copy link
Member

Thank you, @murilohpucci , for your first contribution to CI4!

@murilohpucci
Copy link
Author

Thank you, @murilohpucci , for your first contribution to CI4!

Thank you!

@murilohpucci murilohpucci deleted the feature-add-page-start-end-total-to-page-renderer branch January 7, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.6 enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants