Is there any way I can achieve pagination that uses a dropdown and two buttons (next & previous)?
Attached File(s)
-
Capture.JPG (8.92K)
Number of downloads: 11
Posted 06 January 2013 - 10:06 PM
Capture.JPG (8.92K)
Posted 31 January 2013 - 01:06 PM
Ken Rodriguez, on 06 January 2013 - 10:06 PM, said:
Posted 03 February 2013 - 09:44 AM
class DropPager extends CBasePager
{
public function run()
{//creating dropDownList and next and previous buttons.
echo CHtml::button("<Previous",array("id"=>"prev","disabled"=>$this->currentPage==0?true:false));
echo CHtml::dropDownList("value",$this->currentPage+1,$this->getPageArray(),array("id"=>"drop"));
echo CHtml::button("Next>",array("id"=>"next","disabled"=>$this->currentPage+1!==$this->pageCount?false:true));
$this->registerScript();
}
public function getPageArray() //generating source array for dropdownlist.
{ $arr=array();
for($i=1;$i<=$this->pageCount;$i++)
{
$arr[$i]=$i;
}
return $arr;
}
public function registerScript()
{
Yii::app()->clientScript->registerScript('test','
function updateGrid()
{
var val=$("#drop").val();
$("#drop").parent().parent().yiiGridView("update",{data:{'.$this->pages->pageVar.':val}});
}
$("body").on("change","#drop",updateGrid);
$("body").on("click","#next",function(){
$("#drop").val(parseFloat($("#drop").val()) +1);
updateGrid();
});
$("body").on("click","#prev",function(){
$("#drop").val($("#drop").val()-1);
updateGrid();
});
');
}
}
$("#drop").parent().parent().
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'person-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
"template"=>"\n{pager}{summary}\n{items}",//to lift the pager on th top of the grid.
'pager'=>'DropPager', //Our new pager class.
'columns'=>array(
'id',
'name',
'designation',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
drop.png (23.52K)
Posted 19 April 2013 - 02:37 AM
<?php
class DropPager extends CBasePager {
public function run() {//creating dropDownList and next and previous buttons.
echo Yii::t('main', 'Page Number:');
echo CHtml::button("<Previous", array("id" => "prev", "disabled" => $this->currentPage == 0 ? true : false));
echo CHtml::dropDownList("pageNumber", $this->currentPage + 1, $this->getPageArray(), array("id" => "pageNumberDrop"));
echo CHtml::button("Next>", array("id" => "next", "disabled" => $this->currentPage + 1 !== $this->pageCount ? false : true));
echo " | ";
echo Yii::t('main', 'Page Size:');
echo CHtml::dropDownList("pageSize", $this->pageSize, $this->getPageSizeArray(), array("id" => "pageSizeDrop"));
$this->registerScript();
}
public function getPageArray() { //generating source array for dropdownlist.
$arr = array();
$step = 1;
for ($i = 1; $i <= $this->pageCount; $i+= $step) {
if ($i >= $this->currentPage - 10 && $i - $step < $this->currentPage)
{
$start = max(array($this->currentPage - 10, 1));
$finish= min(array($this->pageCount, $this->currentPage + 10));
for ($i = $start; $i < $finish ; $i++) {
$arr[$i] = $i;
}
}
if ($step * 10 < $i) $step *= 10;
$arr[$i] = $i;
}
return $arr;
}
private function getPageSizeArray() {
$result = array(5 => 5, 10 => 10, 20 => 20, 50 => 50, 100 => 100);
return $result;
}
public function registerScript() {
Yii::app()->clientScript->registerScript('dropPager', '
function updateGrid()
{
pageNumber= parseInt($("#pageNumberDrop").val());
var pageSize = $("#pageSizeDrop").val();
var $x = $("#pageNumberDrop").parent().parent().yiiGridView("update",{data:{' .
$this->pages->pageVar . ':pageNumber, ' .
'pageSize:pageSize}});
}
$("body").on("change","#pageNumberDrop",updateGrid);
$("body").on("change","#pageSizeDrop",updateGrid);
$("body").on("click","#next",function(){
$("#pageNumberDrop").val(parseFloat($("#pageNumberDrop").val()) +1);
updateGrid();
});
$("body").on("click","#prev",function(){
$("#pageNumberDrop").val($("#pageNumberDrop").val()-1);
updateGrid();
});
');
}
}
?>
if (isset($_GET['pageSize'])) {
Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
unset($_GET['pageSize']); // would interfere with pager and repetitive page size change
}return new CActiveDataProvider(get_class($this),array(
'pagination'=>array(
'pageSize'=> Yii::app()->user->getState('pageSize'),
),
'criteria'=>$criteria,
));<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'person-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
"template"=>"\n{pager}{summary}\n{items}",//to lift the pager on th top of the grid.
'pager'=>'DropPager', //Our new pager class.
'columns'=>array(
'id',
'name',
'designation',
array(
'class'=>'CButtonColumn',
),
),
)); ?>