-
Notifications
You must be signed in to change notification settings - Fork 821
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
IsLast doesn’t work when PaginatedList has more than one page #11465
Comments
Hmm, I also can’t seem to use Edit: I haven’t tested |
Regarding the
|
For the functionality, I would expect IsFirst and IsLast to operate on the whole list, not on a page of the list, so with a page size of 6 on a list of 10 items IsLast would only be true for the 10th item, not for the 6th. We don't have a concept of IsLastOnThePage. |
In a future major release maybe the expected behaviour could be changed - but I think for CMS 5 since there was no intentional change to the behaviour, we need to fix the bug by matching the CMS 4 behaviour. Unless we explicitly identify the CMS 4 behaviour as buggy. I think I'd expect it to indicate whether the item is first/last in the current iteration which is what the CMS 4 behaviour did. |
Can reproduce both the expected behaviour in CMS 4 and the presumed buggy behaviour in CMS 5. I've added reproduction details to the issue description. |
Looks like specifically the changes in The same PR changes the iterators to generators, but the generators themselves aren't what's causing this bug (confirmed by moving the change in that method to CMS 4, which then exhibited this same buggy behaviour) Specifically the problem is using That change was necessary because calling |
Implementing this in public function Count(): int
{
return count($this->list->limit($this->getPageLength(), $this->getPageStart()));
} Of course that would mean calling @silverstripe/core-team Does anyone have any thoughts about this? We definitely couldn't implement the above in a patch release. I'd be hesitant to do it in a minor, as well, but could be persuaded... |
The main question is whether Count, IsFirst and IsLast should operate on the current page or the whole list, with an argument a page is also a sublist of the list and if you need to know which is the first and last item of that page to e.g. display different markup, there may not be an easy way of the methods operated on the whole list like they do in CMS 5. Maybe PaginatedList can have special behaviour of the methods aimed at the current page whereas standard ArrayList would operate on the whole list. |
It could be argued any given "page" in a The expected behaviour of template loop scope methods does seem to be that they are specific to the iterator being looped over regardless of the underlying list that iterator comes from.
To be clear, only |
I’ve had a look at this today. To summarise the behaviour: CMS 4 behaviour
Current behaviour
Desired behaviour
To determine whether the item is the very first/last item across all pages, you can do As above, I think adding |
The original design of First/Last was for making alternative styling on when rendering the current view. So "last" meant the last item of the current page. I wouldn't suggest changing this. |
Thank you for the context
Sounds sensible to me, assuming others agree. |
I’ve opened a PR for review: #11471 |
FIX: Make IsFirst and IsLast work as expected for PaginatedList (fixes #11465)
CMS 5 PR merged. @kinglozzer Would you like to tackle the fix for CMS 6 as well? I think changing the count behaviour is probably appropriate, given:
|
Module version(s) affected
5.3.0
Description
In Silverstripe 4,
<% if $First %>
or<% if $Last %>
worked as expected within the scope of the current page. I.e. they would check whether the current item in the iterator is the first/last item on that page.In Silverstripe 5,
$IsFirst
still works this way (it returns true if the item is the first item on that page) but$IsLast
doesn’t work at all in my testing. I would expect it to behave the same way as$Last
did in Silverstripe 4. The bug only occurs when there is more than one page of items, otherwise it works as expected.At this stage I’m not sure if it’s related to the switch from
$First
/$Last
to$IsFirst
/$IsLast
, or related to the change toDataList
to use generators. I suspect the latter, a good way to confirm would be to re-test withArrayList
.How to reproduce
Set up a paginated list (e.g. in your
Page
class):In a template, iterate through that paginated list:
The output in CMS 4:
The output in CMS 5:
Possible Solution
No response
Additional Context
If I add
{$FromEnd}
, it looks likeSSViewer_BasicIteratorSupport
is taking into account the total number of items in the un-paginated list, and not applying either the limit or offset:Validations
silverstripe/installer
(with any code examples you've provided)PRs
CMS 5
CMS 6
TBD
The text was updated successfully, but these errors were encountered: