Hi All,
I want the user to choose how many elements wants to display in cgridview.
In actionAdmin:
if (isset($_GET['pageSize'])) {
Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
unset($_GET['pageSize']);
}
In model:
return new CActiveDataProvider($this, array(
'pagination'=>array(
'pageSize'=> Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']),
),
In the admin view:
echo CHtml::dropDownList('pageSize', 'pageSize', array(10=>10,20=>20,30=>30,40=>40,50=>50),
array(
'onchange'=>"$.fn.yiiGridView.update('teilnehmer-grid',{ data:{pageSize: $(this).val() }})",
));
Everything works fine in this case. But I want to display this dropdownlist instead of "Displaying 1-10…" at the right top of cgridview:
$this->widget('zii.widgets.grid.CGridView', array(
...
'template' => $dialog->link()."{summary}\n{items}\n{pager}",
'summaryText' => 'Elements to display: '.CHtml::dropDownList('pageSize', 'pageSize', array(10=>10,20=>20,30=>30,40=>40,50=>50),
array(
'onchange'=>"$.fn.yiiGridView.update('teilnehmer-grid',{ data:{pageSize: $(this).val() }})",
)),
));
}
In this case it works for all options except "10". Seems like the 10 option remains selected after every selection in this list…any idea?