Getting On Desired Page

Hello Everyone,

       I have Cgridview, which display 10 records per page. I have total 12 records currently. If I create a new user, at that time on successfull creation it will redirected to the again "admin" page. So when I create new user, again redirected to the first page of Cgridview instead of 2nd page. How can I redirected it automatically to the 2nd page?

Thanks in Advance!!!

Hi

If you want to set the current page at the last one the you could use this


$dataProvider->pagination->setItemCount($dataProvider->getTotalItemCount());

$dataProvider->pagination->currentPage = isset($_GET['page']) ?  (int)$_GET['page'] : $dataProvider->pagination->pageCount-1;



then use the dataProvider in CGridview as you already done

Thanks for your answer but still cant get you properly.

In actionCreate function, I have written :

   if($model->save())


       $this->redirect(array('admin'));

So, it will redirected to the first page of admin page gridview. but I want that it will redirect to the last page of it.

Hi,try this


$this->redirect(array('admin?id='.$model->id));

Not working…

It gives php error like " $model has not vaalue as id".

About that, you have to set the action with parameter like actionAdmin($id=null) but this is not the point

please post the code and the place (in which action or view file) that I have mentioned

Let me explain you exact code.

I have a grid in which ther are many no. of rows and each row has one link named as "Data" that will redirect to the other page. So If I am on 19th page of the grid and press on "Data" link at that time it will redirect me to other page but when I press back button from browser, It will come to the Original page of Grid but on the 1st page instead of 19th.

just you want to add on action


public function actionCreate($id == ''){

   //if value save this page redirect this id..

   $this->redirect(array('admin?id='.$model->id));

}

please try it…

Pleach check some values with that:


$dataProvider->pagination->setItemCount($dataProvider->getTotalItemCount());

var_dump($_POST);

var_dump($_GET);

var_dump($dataProvider->pagination->pageCount-1);

$dataProvider->pagination->currentPage = isset($_GET['page']) ?  (int)$_GET['page'] : $dataProvider->pagination->pageCount-1;

var_dump($dataProvider->pagination->currentPage);

post the results