I have found that my admin users can sort and filter CGridView data tables just fine. But it fails to work for non-admin users. When I first pull up the page:
[indent]admin shows: "Displaying 1-[color="#009900"]20[/color] of 21 result(s)."
non-admin shows: "Displaying 1-[color="#990000"]21[/color] of 21 result(s)."[/indent]
Note that the [color="#009900"]green[/color] reflects the correct text and [color="#990000"]red[/color] the incorrect.
If I filter by a field that should result in no results:
[indent]admin shows: nothing (which is correct)
non-admin shows: "[color="#990000"]Displaying -20-0 of 0 result(s).[/color]" and the list does not change.
[/indent]
If I click on a column to sort, the admin sorts correctly, the non-admin shows the sorting icon next to the column header, but the data does not change sort order.
VIEW
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'afterAjaxUpdate'=>'attachMenu',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array('name'=>'nProductID', 'htmlOptions'=>array('width'=>20)),
array('name'=>'nProductClassID', 'value'=>'$data->ClassR->strProductClass', 'htmlOptions'=>array('width'=>60), 'filter'=>CHtml::listData(ProductClass::model()->findAll(array('order'=>'strProductClass')), 'nProductClassID', 'strProductClass')),
array('name'=>'strProductCode', 'htmlOptions'=>array('width'=>55)),
array('name'=>'strSKU', 'htmlOptions'=>array('width'=>90)),
array('name'=>'strTitle', 'value'=>'$data->strTitle', 'htmlOptions'=>array('style'=>'text-align: left')),
array('name'=>'curPrice', 'value'=>'"$".$data->curPrice', 'htmlOptions'=>array('width'=>40)),
array('name'=>'nPublisherID', 'value'=>'$data->PublisherR->strPublisher', 'htmlOptions'=>array('width'=>150, 'style'=>'text-align: left'), 'filter'=>Publisher::filterList()),
array('name'=>'nPDFStatusID', 'value'=>'$data->PDFStatusR->strPDFStatus', 'htmlOptions'=>array('width'=>60, 'style'=>'text-align: left'), 'filter'=>CHtml::listData(PDFStatus::model()->findAll(array('order'=>'nPDFStatusID')), 'nPDFStatusID', 'strPDFStatus')),
array('name'=>'bHidden', 'value'=>'boolAsYesNo($data->bHidden, false)', 'htmlOptions'=>array('width'=>40), 'filter'=>array(0=>"No", 1=>"Yes")),
array('name'=>'dateAdded', 'value'=>'dateFormat("Y-m-d", $data->dateAdded, "Unknown")', 'htmlOptions'=>array('width'=>70)),
array(
'class'=>'CButtonColumn',
),
),
));
MODEL:
public function search() {
$criteria = new CDbCriteria;
$userObj = Yii::app()->getModule('user');
$user = $userObj->user();
$pubid = ($userObj->isAdmin()) ? $this->nPublisherID : $user->nPublisherID;
$criteria->with = array('ClassR', 'PublisherR', 'PDFStatusR');
$criteria->compare('nProductID',$this->nProductID,true);
$criteria->compare('t.nProductClassID',$this->nProductClassID);
$criteria->compare('strProductCode',$this->strProductCode,true);
$criteria->compare('strSKU',$this->strSKU,true);
$criteria->compare('strTitle',$this->strTitle,true);
$criteria->compare('curPrice',$this->curPrice);
$criteria->compare('PublisherR.nPublisherID',$pubid);
$criteria->compare('PDFStatusR.nPDFStatusID',$this->nPDFStatusID);
$criteria->compare('bHidden',$this->bHidden);
$criteria->compare('dateAdded',$this->dateAdded);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array('PageSize'=>20),
));
}
I am aware that I am sorting in the model based on whether the user is an admin or not. This was my first thought. Even if I take out this code, it still functions the same way.
Any thoughts?