手动更新Cgridview使用其列值

时间:2014-01-04 08:11:09

标签: yii

我想使用其列值更新cgridview,例如,如果我想从网格中过滤名称'xxx',如何在

中执行此操作
 $.fn.yiiGridView.update("editstructure-grid");

DataProvider代码:

'dataProvider'=>$model->searchbyID($base),

模型搜索()代​​码:

public function searchbyID($id)
    {
        // @todo Please modify the following code to remove attributes that should not be searched.
        echo 'SEARCH ID===>'.$id;
        $criteria=new CDbCriteria;

        $criteria->compare('crm_field_id',$this->crm_field_id);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('display_rules',$this->display_rules,true);
        $criteria->compare('edit_rules',$this->edit_rules,true);
        $criteria->compare('type',$this->type);
        $criteria->compare('is_deduplication_field',$this->is_deduplication_field);
        $criteria->compare('is_std_phone',$this->is_std_phone);
            $criteria->compare('crm_base_contact_id',$id);
        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }

1 个答案:

答案 0 :(得分:0)

这会有点复杂,所以请仔细阅读,

您需要将点击的元素文本发送回dataProvider,并使用它来过滤掉结果并再次生成网格:

我会留下那个值给你选择,

让我们刷新网格并发回一些数据:

 $.fn.yiiGridView.update('some_grid', {
        data: 'name=tiny', // I'll assume you have selected the value and it's tiny
 });

但在此之前如何触发此发送方法?一种方法是,当你给出gridview的列

时,你可以把它放在元素onclick属性上
$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  . '"');
 }