doubi8512 2012-03-31 19:47 采纳率: 0%
浏览 23
已采纳

Yii CGridview没有过滤

I'm trying to work with a YII CGridview to display some data.

This is home my model search function looks like:

/**
 * Retrieves a list of models based on the current search/filter conditions.
 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
 */
public function search()
{
    $criteria=new CDbCriteria;
    $criteria->compare('ip',$this->ip,true);
    $criteria->compare('first_use',$this->first_use,true);
    $criteria->compare('last_use',$this->last_use);
    $criteria->compare('memberid',$this->memberid);
    $criteria->compare('countryid',$this->countryid);

    return new CActiveDataProvider(get_class($this), array(
        'criteria'=>$criteria,
    ));
}

And this is how my view looks like

$this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'iplog-grid',
        'dataProvider'=>$oIPLog->search(),
        'filter'=>$oIPLog,
        'summaryText' => 'showing you {start} - {end} of {count} logged Ips',
        'columns'=>array(
            array(
                'name'=>'ip',
                'type'=>'raw',
            ),
            array(
                'name'=>'first_use',
                'type'=>'datetime',
            ),
            array(
                'name'=>'last_use',
                'type'=>'datetime',
            ),
        ),
    ));

Displaying the CGridview works, but I can't seem to get the filter on top of it to work. It sends the call and I don't get any error as reponse, it just returns the whole unfiltered data again..

Any clues?

  • 写回答

2条回答 默认 最新

  • dousi4257 2012-03-31 20:00
    关注

    And how exactly does your controller look like?

    For the CGridview filter to work you need to check in your controller if there are any filters set and then return the filtered object.

    To clarify, something like this should be placed into your controller action

    $oObject = new Object('search');
    if (isset($_GET['Object'])) {
        $oObject->attributes = $_GET['Object'];
    }
    

    Hope this helps

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

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?