I have a TYPO3 page that lists items using QueryResultInterface
filters.
So I am using setOffset
and setLimit
to get partial results, and ajax to get more results when required.
The part I'm not sure about is how to get the total number of filtered results on the frontend so that I can let javascript know when it has reached the end?
I've figured out that if I do this:
$query = $this->createQuery();
...filters...
$total = $query->count();
$query->setOffset($myoffset);
$query->setLimit($mylimit);
$query2 = $query->execute();
$query2[total] = $total;
return $query2;
I get the unfiltered total as an integer in my array and can access using {myitems.total}
in the fluid template.
If I $total = $query->execute()->count();
I get the right number but would defeat the purpose of breaking up the data...
A work around method I thought of was to simply set the limit +1 higher. So if I want 10 I instead set it to 11.
Then in the fluid template add a condition to avoid rendering the last item:
<f:for each="{items}" as="item" iteration="i">
<f:if condition="{i.index} < 10">
...
</f:if>
</f:for>
Elsewhere in the template I can now check the existance of the 11th item and add a class if it doesn't exist:
{f:if(condition:'!{items.10}', then:'nomore')}
This avoids the need to know the total number.