Yii 手动使用其列值更新Cgridview
我想使用其列值更新cgridview,例如,如果我想从网格中筛选名称“xxx”,如何在Yii 手动使用其列值更新Cgridview,yii,Yii,我想使用其列值更新cgridview,例如,如果我想从网格中筛选名称“xxx”,如何在 $.fn.yiiGridView.update("editstructure-grid"); 数据提供程序代码: 'dataProvider'=>$model->searchbyID($base), 模型搜索()代码: 这会有点复杂,所以请仔细阅读 您需要将单击的元素文本发送回数据提供商,然后使用该文本过滤结果并再次生成网格: 我会让你选择这个值 让我们刷新网格并发回一些数据: $.fn.
$.fn.yiiGridView.update("editstructure-grid");
数据提供程序代码:
'dataProvider'=>$model->searchbyID($base),
模型搜索()代码:
这会有点复杂,所以请仔细阅读 您需要将单击的元素文本发送回数据提供商,然后使用该文本过滤结果并再次生成网格: 我会让你选择这个值 让我们刷新网格并发回一些数据:
$.fn.yiiGridView.update('some_grid', {
data: 'name=tiny', // I'll assume you have selected the value and it's tiny
});
但在此之前,如何触发此发送方法?一种方法是,当您给出gridview的列时,可以将它放在elementsonclick
属性上
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'some_grid',
'dataProvider' => $dataProvider,
'columns' => array(
array(
'name' => 'name' ,
'header' => Yii::t('model','name'),
'value' => 'CHtml::link($data["name"], "#", array("onclick" => "RefreshMyGrid(".$data["name"]."); return false;"))',
'type' => 'raw',
),
然后你的函数变成这样:
function RefreshMyGrid(Word){
$.fn.yiiGridView.update('some_grid', {
data: 'name='+Word, // Word is what you are sending now
});
}
然后在数据提供程序被填充的地方(无论是在模型search()
函数中还是…),获取该值并使用该值进行筛选
希望有帮助:D
更新:
在searchbyID
中获取传递的参数:
// name here is the parameter that we sent from the grid
$param = Yii::app()->request->getParam('name' , null);
if(!empty($param))
{
// t is alias for your table, also make proper join here
$criteria->join = 'INNER JOIN yourTable yt ON t.id = yt.id';
// add a condition on joined table
$criteria->addCondition('yt.id = "' . $param . '"');
}
如果您不了解yii的文档,另一种选择是。。。使用datatables.net-它实际上不在cgridview中显示crm_base_contact_id列,而是在模型类中使用,在ajaxsubmitbutton上,如您所建议的,成功通过传递的id进行网格更新,但数据不过滤我的代码:array('success'=>'function(){$.fn.yiiGridView.update(“editstructure grid”{data:“crm_base_contact_id=1087”});}'))你在哪里处理
crm_base_contact_id
?你需要在哪里处理?你需要在哪里填充你的数据提供程序crm_base_contact_id是另一个表的外键你找到你要找的东西了吗?我在粘贴了上面的代码后得到这个错误”CWebApplication及其行为没有名为“getParam”的方法或闭包
// name here is the parameter that we sent from the grid
$param = Yii::app()->request->getParam('name' , null);
if(!empty($param))
{
// t is alias for your table, also make proper join here
$criteria->join = 'INNER JOIN yourTable yt ON t.id = yt.id';
// add a condition on joined table
$criteria->addCondition('yt.id = "' . $param . '"');
}