2 zerovszero1 zerovszero1 于 2014.07.14 17:58 提问

yii zii.widgets.grid.CGridView 筛选失败

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'fl-navigation-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'pager'=>array(

'class'=>'CLinkPager',
'header'=>'',
'cssFile'=>'amdin_css.css',
),

'htmlOptions'=>array('class'=>'FlList'),
'template'=>'{items}{pager}{summary}',
'columns'=>array(
       array(
        'name'=>'CityId',
        'headerHtmlOptions'=>array(
            'width'=>'80px',
        ),
        'value'=>'empty($data->City->City)?$data->CityId:$data->City->City',
        'filter'=>GetAllDbData::getInstance()->getModelData('fl_navigation','FlCity','CityId','City'),   
    ), 
       array(
        'name'=>'ClassId',
        'headerHtmlOptions'=>array(
            'width'=>'100px',
        ),

         'value'=>'empty($data->Class->ClassName)?$data->ClassId:$data->Class->ClassName',

        'filter'=>GetAllDbData::getInstance()->getModelData('fl_navigation','FlClass','ClassId','ClassName'),   

    ),)
 ));

其中public function getModelData($Table, $DoModel, $GetId, $GetName, $where = '') {
$arr=array();
$cityData = array();
$connection = Yii::app ()->db;
$sql = " select distinct {$GetId} from {$Table} ";
$command = $connection->createCommand ( $sql );
$result = $command->queryAll();
if (! $result) { // 如果为空返回空
return;
} else {
foreach ( $result as $v ) {
$allowId = $v [$GetId];
$data [] = $DoModel::model ()->findAll(
array(
'select'=>''.$GetId.','.$GetName.'',
'condition' => ''.$GetId.'='.$allowId.' '.$where.'',

                    )
            );
        }
        foreach ( $data as $value ) {
            foreach ( $value as $v ) {
                $arr [] = $v;
            }
        }
        if($arr){
            $cityData = CHtml::listData ( $arr, $GetId, $GetName );
        }
        //$cityData [0] = '全部';
        return $cityData;
    }
}

城市可以实现筛选,而分类不可以实现筛选想知道答案!

Csdn user default icon
上传中...
上传图片
插入图片