Paginator: Find The Page Of An Item

I have a pager and i want to set the currentPage based on where is an item. How can I know what’s this page?

Could you make your question more clear please?

say that I have a 30 items and the pagination is 10 items per page

to display the 15th item I need to go to page 2

I need a general purpose formula to get that page knowing item requested, items per page and number of pages

actually I ended up with this:

In fact you should use functions like $provider->getData()

then you should search in this data either with raw php code or with another Yii function (if exist) to get the index of the collection of getData()

Then as you said

"$itemPage = (int) ceil(($itemPosition * $provider->pagination->pageCount) / $provider->totalItemCount);"

and use it in parameters of DataProvider like

‘pagination’ => array(

            'pageSize' => 2,

            'currentPage' => $itemPage,


:) that’s what I’ve done but if there’s a smarter way… let me know

actually I cant get a consistent $itemPosition fetching provider data, seems not the same order as displayed

Ok I’ve found this smarter way to achieve that ;)


        for ($p = 1; $p <= $adapter->pagination->pageCount; $p++) {

          if (in_array($this->viewMessage, $adapter->getKeys(true))) break;




So the current page will be the page of the requested element (in this case $this->viewMessage is the id i’m looking for)