khushal
(Khushal Fadiya)
August 19, 2013, 9:16am
1
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!!!
konapaz
(Konapaz)
August 19, 2013, 9:49am
2
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
khushal
(Khushal Fadiya)
August 19, 2013, 9:56am
3
KonApaz:
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.
Ankit_Modi
(Ankit Modi)
August 19, 2013, 10:12am
4
Hi,try this
$this->redirect(array('admin?id='.$model->id));
khushal
(Khushal Fadiya)
August 19, 2013, 10:40am
5
Not working…
It gives php error like " $model has not vaalue as id".
konapaz
(Konapaz)
August 19, 2013, 11:00am
6
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
khushal
(Khushal Fadiya)
August 19, 2013, 11:32am
7
KonApaz:
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.
Ankit_Modi
(Ankit Modi)
August 19, 2013, 11:46am
8
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…
konapaz
(Konapaz)
August 19, 2013, 8:26pm
9
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.
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