关于Yii中CGridView关联表字段的filter问题解决方法
来源:互联网 发布:行业分析报告 知乎 编辑:程序博客网 时间:2024/05/29 15:31
http://blog.sina.com.cn/s/blog_4291fcdb0100tzrt.html
当你想用CGridView控件来生成一个Grid表格的时候,是非常方便的,你只需要简单的指定几个属性就可以了,比如:
首先,让关联表字段显示在Grid表格里面很容易,你可以在dataProvider属性加上关联表,然后columns属性里直接加上要显示的关联表属性就可以,比如,修改后的dataProvider为
'dataProvider'=>$model->with('relationNameToOtherTable
修改后的columns属性为:
'columns'=>array(
),
但这时的customer_nm是不具备filter域的
解决方法如下:(修改主表对应的Model类)
1)手动为主表增加关联表属性,public $this->customer_nm;
2) 修改search()方法,增加如下两行:$criteria->with ='relationNameToOtherTable';//relationNameToOtherTable是你在relations里面定义的键值
$criteria->compare('customer_nm',$this->customer_nm);
3)增加afterFind()方法到主表的model类,方法内容如下:$this->customer_nm=$this->relationNameToOtherTable->customer_nm;
这时,你就可以不像前面写的那样修改dataProvider和columns了,因为你手动增加的那个属性已经把关联表的字段属性加进来了,直接用就可以了,最终view代码如下:
'dataProvider'=>$model->search();
'columns'=>array(
'id',
'customer_cd',
'customer_nm'=>array(
'name'=>'relationNameToOtherTable.customer_nm',
),
),
ok, that's all, not the best solution, but it works any way, wellif you have some good ideas for this kind of problem feel free totell me, thanks a lot!!
1)手动为主表增加关联表属性,public $this->customer_nm;
2) 修改search()方法,增加如下两行:$criteria->with ='relationNameToOtherTable
$criteria->compare('customer_nm',$this->customer_nm);
3)增加afterFind()方法到主表的model类,方法内容如下:$this->customer_nm=$this->relationNameToOtherTable
这时,你就可以不像前面写的那样修改dataProvider和columns了,因为你手动增加的那个属性已经把关联表的字段属性加进来了,直接用就可以了,最终view代码如下:
'dataProvider'=>$model->search();
'columns'=>array(
),
ok, that's all, not the best solution, but it works any way, wellif you have some good ideas for this kind of problem feel free totell me, thanks a lot!!
http://blog.sina.com.cn/s/blog_4291fcdb0100tzrt.html
0 0
- 关于Yii中CGridView关联表字段的filter问题解决方法
- yii 关联表字段排序
- Yii关联表字段查询
- yii CGridView 分页 初始化 js的方法
- SAS中关联表字段类型不同时的解决办法
- Yii框架中CGridView的使用方法
- Yii以关联表字段为条件进行查询
- 根据基础数据表id获取数据库中关联表字段内容方法
- ORACLE 中查询表字段信息的方法
- ORACLE 中查询表字段信息的方法
- ORACLE 中查询表字段信息的方法
- Oracle中查看表字段和注释的方法
- Yii中CGridView使用心得
- Yii框架中CGridView的使用方法以及详细示例
- Yii框架中CGridView的使用方法以及详细示例
- Yii中CGridView单元格组件和数据提供者的使用
- Yii框架中CGridView的使用方法以及详细示例
- Yii使用renderPartial绘制的CGridView中checkall功能无效
- [从头学数学] 第277节 [计算几何] 任意多边形的内角
- 9. Palindrome Number
- HDU 1087 Super Jumping! Jumping! Jumping! 上升序列最大和+DP .
- {JavaScript学习图谱}作为HTML5的开发的脚本有必要知道一下!
- android多线程下载图片
- 关于Yii中CGridView关联表字段的filter问题解决方法
- 剑指Offer——笔试题+知识点总结
- JQuery总结之——选择器
- <Learning SQL> O'REILLY_Chap. 3_查询入门
- Android多线程分析之一:使用Thread异步下载图像
- Java并发编程学习——基础构建模块
- Android程序员之死
- Android–多线程之Handler下载图片源码
- dstat工具