fix(datatables): keep the per-page control in sync with perPage - #289
Merged
Conversation
`perPage` was passed through without being checked against `perPageSelect`. When the value is not one of the offered options the select falls back to rendering its first entry while the table pages at the requested size, so the control and the behaviour disagree and nothing signals it -- the reader sees "5" above a page of 25 rows, and the only way to notice is to count them. Insert the value into the option list instead. That honours the author's intent and makes the control show what is actually happening. Of the three available outcomes -- inject, or warn and fall back, or render a mismatched value -- the last is the worst, because it is silent. The value lands in sorted position among the numeric entries, so "All" (a [label, value] pair with value -1) stays last. Entries are compared through a helper that reads either shape. Measured on a real site with `perPage: 25` against the default options: before select "5", 25 rows rendered, options 5/10/20/50/All after select "25", 25 rows rendered, options 5/10/20/25/50/All A value already present is untouched: `perPage: 10` still yields 5/10/20/50/All with the select on 10 and no injection. `pnpm test` passes.
Contributor
Author
|
🎉 This PR is included in version 4.1.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The defect
perPagewas passed straight to simple-datatables without being checked againstperPageSelect. When the value is not one of the offered options, the select falls back to rendering its first entry while the table pages at the requested size — so the control and the behaviour disagree, and nothing signals it.The reader sees "5" above a page of 25 rows. The only way to notice is to count them.
Measured on a real site with
perPage: 25against the default options:The fix
Insert the value into the option list. That honours the author's intent and makes the control show what is actually happening:
Of the three available outcomes — inject, warn and fall back, or render a mismatched value — the last is the worst, because it is silent. Injecting is closest to intent, since
perPageis an explicit request.Details
The value lands in sorted position among the numeric entries, so "All" stays last. Entries may be a bare number or a
[label, value]pair (that is how "All" carries-1), so the comparison reads the value in either shape and the sort ignores non-positive values.A value already present is untouched:
perPage: 10still yields5/10/20/50/Allwith the select on 10 and no injection.Related
A build-time counterpart shipped in mod-blocks#185, which warns at Hugo time when a
listblock'spaginationis not a selectable size. That catches the common authoring path early but cannot cover callers reaching this module directly, or a customperPageSelect— hence this runtime fix as well.Checks
pnpm testpasses. Both cases exercised in a browser on a real 106-row table.