likeradio
(Likeradio)
July 14, 2011, 9:26am
1
my code is:
==Conroller==
$page = new CPagination();
$page->setCurrentPage(1);
$this->render(‘index’,array(
‘data’ => new CArrayDataProvider($data,array(‘pagination’=>$page)),
));
==view==
$this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'data-grid',
'selectableRows' => 0,
'dataProvider'=>$data,
'selectableRows'=>0,
'columns'=>array(
.....
));
I want to show the page 2 when opened,and it work;
but then I click the page number,it not work.
sorry ,my english is very poor.
By
$page->setCurrentPage(1)
you’re forcing the paginator to show the first page over and over again. Try this in your view:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'data-grid',
'selectableRows'=>0,
'dataProvider'=>new CArrayDataProvider($data),
'columns'=>array(...),
)); ?>
Now feed your actual data (i.e. not a CArrayDataProvider!) to the $data variable in your view. You might have to set the id and keyField properties as well.
likeradio
(Likeradio)
July 15, 2011, 1:29am
3
Thx for your help.But I want to show page2 when page initial and user can change the page by click.How?
By
$page->setCurrentPage(1)
you’re forcing the paginator to show the first page over and over again. Try this in your view:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'data-grid',
'selectableRows'=>0,
'dataProvider'=>new CArrayDataProvider($data),
'columns'=>array(...),
)); ?>
Now feed your actual data (i.e. not a CArrayDataProvider!) to the $data variable in your view. You might have to set the id and keyField properties as well.
softark
(Softark)
July 15, 2011, 3:48am
4
By checking the source HTML code of a CGridView page, you will notice that a link button in the pager has a page parameter in it.
A link to the 2nd page should be something like the following:
/path/to/the/page?DataName_page=2
I think you can use it for the entry link to the page.
BTW, why do you want to show the 2nd page as the initial display?
The number of the total pages should vary case by case.
Do you mean the last page by it? If so, isn’t it possible to satisfy your needs by reversing the sorting order?
likeradio
(Likeradio)
July 15, 2011, 6:35am
5
thank you very much ,the problem already solved.
softark:
By checking the source HTML code of a CGridView page, you will notice that a link button in the pager has a page parameter in it.
A link to the 2nd page should be something like the following:
/path/to/the/page?DataName_page=2
I think you can use it for the entry link to the page.
BTW, why do you want to show the 2nd page as the initial display?
The number of the total pages should vary case by case.
Do you mean the last page by it? If so, isn’t it possible to satisfy your needs by reversing the sorting order?
Because I want to show the row which user select last time.The row may at page2 or last page.
softark
(Softark)
July 15, 2011, 8:01am
6
I see. It’s one of the common needs.
How did you solve that? Could you share your experience?
likeradio
(Likeradio)
July 15, 2011, 9:14am
7
change code like this:
==Conroller==
[color="#FF0000 "]if(isset($_GET[‘dataname_page’]))
$selection = $_GET[‘dataname_page’];
else
$selection = $count_page;[/color]
$page = new CPagination();
[color="#FF0000 "]$page->setCurrentPage($selection - 1);[/color]
$this->render(‘index’,array(
‘data’ => new CArrayDataProvider($data,array(‘pagination’=>$page)),
));
==view==
$this->widget(‘zii.widgets.grid.CGridView’, array(
‘id’=>‘data-grid’,
‘selectableRows’ => 0,
‘dataProvider’=>$data,
‘selectableRows’=>0,
‘columns’=>array(
…
));