to my understanding I need to provide the number of results to the CSqlDataProvider to get pagination to work with CListView. My problem is that I have a pretty complex and "heavy" query I do not want to run twice. Does anyone have a nice way to do this without running the query twice? Or any other good advise?
The pagination has to know how many page items to display and you have to assign the ‘totalItemCount’.
Maybe you have a simple query to get this value. Then you can override the ‘getTotalItemCount’ of the CSqlDataProvider or set ‘totalItemCount’ to this value.
Another solution - but very, very ‘heavy’ - and I wouldn’t do this:
You can fetch all records at once and create a CArrayDataProvider with the results from $dataProvider->getData();
But then this is a ‘fake’ pagination where always all items are fetched instead of only the items of a single page.
Since this is a part of a "search engine" on my site, I cannot shorten the query. So the only real solution I could find is to run it twice, and set the count from the first round. I am not sure how grave the consequenses will be regarding load and execution time in production.