I’m having some difficulty getting pagination to work right after using sort on a column. What happens is after I sort a column and I attempt to move on to the next page, then the columns aren’t sorted anymore. It’s as if a call was made to the dataprovider without taking into consideration that I want to sort a column(the next page is exactly the same as the page when the sort is not used).
The model I’m using extends from CFormModel. Within this model I have a method called getSqlDataProvider().
$sql='SELECT TQTY as tqty, TPROD as tprod from ITHI';
$dataProvider=new CSqlDataProvider($sql, array(
'totalItemCount'=>$count,
'id'=>'myDataProvider',
'keyField'=>'tid',
'sort'=>array(
'attributes'=>array(
'tqty',
),
),
'pagination'=>array(
'pageSize'=>10,
),
));
return $dataProvider;
This is the action used in my controller
$model=new Ibltwo('search');
$model->unsetAttributes();
if(isset($_GET['Ibltwo']))
$model->attributes=$_GET['Ibltwo'];
$this->render('index',array(
'model'=>$model,
));
And this is the code in my view file that displays the grid.
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'ibl-grid',
'dataProvider'=>$model->getSqlDataProvider(),
'selectableRows'=>2,
'columns'=>$colArray,
));
for $colArray, here's a small snippet of it( it's huge )
.
.
array(
'name'=>'tqty',
'value'=>'strip_tags($data[\'tqty\'])',
'header'=>Yii::t('order', 'Order total'),
'type'=>'raw',
'htmlOptions'=>array(
'style'=>'text-align:right;',
)),
.
.
Would appreciate any suggestions or help.