I’ve been struggling building an application using the Yii framework; I’ve managed to get most of the problems sorted by now, however, I’m still stuck with a weird pagination error.
I have a page with a gridview. There are many relations in the search filters (which all function fine), however, the pagination doesn’t function correctly. In this example, I’ve put in 2 items. Item #1 has amount 13, Items #2 has amount 2. For design reasons, each amount has its own row, so when one item with amount 13 is stored, 13 rows are stored in the table. In the example above, the pagination shows the following: Displaying 1-2 of 15 result(s).
The first part seems to be ok (there are only 2 results in the current page; however, the amount of results is off. This causes the pagination to think there are more pages to display results (I’ve set the pagelimit to 10), so the gridview gives me 2 pages of ‘data’, which of course is incorrect (second page just is an empty resultset).
In my search function, I’ve identified the problem line I think:
$criteria->with = array('stores_rel','neworders_rel','items_rel','suppliers_rel');
If I comment this line, the result set seems to be ok (Displaying 1-2 of 2 result(s).), however, my search filters won’t work anymore.
When I test the original query from the Yii debugger, my rowcount is 2 (as expected), however, the Itemcount function still returns 13 somehow.
I’ve searched the internet (with friend google) and the Yii website, but haven’t found anything with a solution in it. Anyone has a clue how to force the correct itemcount on the gridview?
NOTE: this only seems to happen with relations. Is there a secret line of code to include in gridview or the search function?
Right now the search function has the following elements:
$criteria->group (combine similar entries)
$criteria->scopes (sum the amount of items)
$criteria->with (including relations to make the search filter work)
$criteria->condition (the usual stuff)
If anyone has any ideas whether it should be considered a bug or if my code is missing some vital ‘initializer’ to make it work?
Thanks in advance.