doubi8512 2012-03-31 11: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:

  1. /**
  2. * Retrieves a list of models based on the current search/filter conditions.
  3. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  4. */
  5. public function search()
  6. {
  7. $criteria=new CDbCriteria;
  8. $criteria->compare('ip',$this->ip,true);
  9. $criteria->compare('first_use',$this->first_use,true);
  10. $criteria->compare('last_use',$this->last_use);
  11. $criteria->compare('memberid',$this->memberid);
  12. $criteria->compare('countryid',$this->countryid);
  13. return new CActiveDataProvider(get_class($this), array(
  14. 'criteria'=>$criteria,
  15. ));
  16. }

And this is how my view looks like

  1. $this->widget('zii.widgets.grid.CGridView', array(
  2. 'id'=>'iplog-grid',
  3. 'dataProvider'=>$oIPLog->search(),
  4. 'filter'=>$oIPLog,
  5. 'summaryText' => 'showing you {start} - {end} of {count} logged Ips',
  6. 'columns'=>array(
  7. array(
  8. 'name'=>'ip',
  9. 'type'=>'raw',
  10. ),
  11. array(
  12. 'name'=>'first_use',
  13. 'type'=>'datetime',
  14. ),
  15. array(
  16. 'name'=>'last_use',
  17. 'type'=>'datetime',
  18. ),
  19. ),
  20. ));

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 12: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

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

    Hope this helps

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部