drvxnivoqf17568697 2014-05-21 10:20
浏览 42
已采纳

在CGridView(YII)中不工作过滤器

Not working filter elements in the CGridView. Tell me how to fix this? For example, you must select a category, choose "Baby", but nothing happens. enter image description hereSiteController

public function actionIndex()
    {
        $model = new Page;
        $dataProvider=new CActiveDataProvider('Page', array(
            'criteria'=>$criteria,
            'sort' => array(
                'defaultOrder'=>array(
                    'created'=>"DESC"
                )),
            'pagination'=>array(
                'pageSize'=>30,
            ),
        ));

        // renders the view file 'protected/views/site/index.php'
        // using the default layout 'protected/views/layouts/main.php'
        $this->render('index', array('dataProvider'=>$dataProvider,'model'=>$model));
    }

index.php

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $dataProvider,
    'enableSorting'=>true,
    'filter'=>$model,
    'columns' => array(
        'title' => array(
            'name'=>'title',
            'type'=>'raw',
            'value'=>'CHtml::link($data->title,Yii::app()->request->baseUrl."/page/".$data->id)',
            'headerHtmlOptions' => array('style'=>'width:250px;'),
        ),
        'created' => array(
            'name' => 'created',
            'value' => 'date("j.m.Y H:i", $data->created)',
            'headerHtmlOptions' => array('style'=>'width:90px;'),
            'type'=>'raw',
        ),
        'category_id' => array(
            'name' => 'category_id',
            'value' => '$data->category->title',
            'filter' => Category::allCategory(),
            'headerHtmlOptions' => array('style'=>'width:150px; text-align:center;'),
            'type'=>'raw',
            'sortable'=>TRUE
        ),
        'subcategory_id' => array(
            'name' => 'subcategory_id',
            'value' => '$data->subcategory->title',
            'filter' => Subcategory::allCategory(),
            'headerHtmlOptions' => array('style'=>'width:150px; text-align: center;'),
            'type'=>'raw',
        ),
        'condition_id' => array(
            'name' => 'condition_id',
            'value'=> '$data->condition->title',
            'filter' => Condition::allAttributes(),
            'headerHtmlOptions' => array('style'=>'width:90px;'),
            'type'=>'raw',
        ),
    ),
));

Thanks in advance for answers and assistance.

  • 写回答

2条回答 默认 最新

  • dsebywql016137 2014-05-21 10:46
    关注

    You do not load the POST/GET data from the request, and that is why you do not get any filtered values. There are more approaches to this, I show you a simple one i use mostly;

    in your controler do this:

        $model = new Page;
        if(isset($_GET['Page']))
            $model->attributes =$_GET['Page'];
    
    
            $dataProvider = $model->search();
    

    In you Page model, find the search function, and adapt your custom Dataprovider there (or make a copy ot the search and use it later)

    That should do the job. The important part is - you have to set the attributes somewhere, from the GET request.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂