页面加载时的 CGridview 过滤器,在搜索字段中使用预定义值 [英] CGridview filter on page load with pre define value in search field

查看:20
本文介绍了页面加载时的 CGridview 过滤器,在搜索字段中使用预定义值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Yii 框架.

我使用以下方法在我的 cgridview 过滤器字段之一中设置了一个值:

这是我的 jQuery,用于为搜索字段赋值:

$('#gridviewid').find('input[type=text],textarea,select').filter(':visible:first').val('".$_GET['value']."');

这里是我调用 cgridview 的 PHP:

$this->widget('zii.widgets.grid.CGridView', array('id'='=>'账单网格','dataProvider'=>$dataProvider,'过滤器'=>$模型,'cssFile'=> Yii::app()->baseUrl .'/css/gridview.css','寻呼机'=>数组('class'=''AjaxList','maxButtonCount'=>25,'标题'=>''),'列' =>$dialog->columns(),'template'=>"<div class=\"tools\">".$dialog->link()."&nbsp;&nbsp;&nbsp;".CHtml::link($xcel.'导出到excel', array('ExcelAll'))."</div><br/>{items}{summary}<div class=\"pager-fix\">{寻呼机}

",));

该值出现在搜索字段中,我的 cgridview 正常工作,没有任何问题,但我无法触发 cgridview 刷新或过滤.有谁知道在页面加载后使用预定义值触发 cgridview 进行过滤吗?

我们将不胜感激,如果您需要更多信息,请告诉我.

谢谢.

解决方案

无需任何客户端代码修改即可解决问题.在您的控制器操作中,只需设置属性的默认值,如下所示

公共函数 actionAdmin(){$model = new Bills();$model->unsetAttributes();$model->attribute_name="default filter value";//其中attribute_name 是您希望在过滤器搜索字段中为其设置默认值的属性if(isset($_GET['Bills'])){$model->attributes = $_GET['Bills'];}$this->render('admin',array('model'=>$model));}

I am working with the Yii framework.

I have set a value in one of my cgridview filter fields using:

Here is my jQuery to assign a value to the searchfield:

$('#gridviewid').find('input[type=text],textarea,select').filter(':visible:first').val('".$_GET['value']."');

And here my PHP for calling the cgridview:

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'bills-grid',
'dataProvider'=>$dataProvider,
'filter'=>$model,
'cssFile'=>Yii::app()->baseUrl . '/css/gridview.css',
'pager'=>array(
    'class'=>'AjaxList',
    'maxButtonCount'=>25,
    'header'=>''
),
'columns' => $dialog->columns(),
'template'=>"<div class=\"tools\">".$dialog->link()."&nbsp;&nbsp;&nbsp;".CHtml::link($xcel.'  Export to excel', array('ExcelAll'))."</div><br />{items}{summary}<div class=\"pager-fix\">{pager}</div>",));

The value appears in the search field and my cgridview works correctly without any issues, but I am unable to trigger the cgridview to refresh or filter. Does anyone know who to trigger the cgridview to filter after page load with a predefined value?

Any help would be greatly appreciated and please let me know if you need additional information.

Thank you.

解决方案

You can solve the problem without any clientside code modification. In your controller action just set the default value for the attribute as shown below

public function actionAdmin()
{
    $model = new Bills();
    $model->unsetAttributes();
    $model->attribute_name="default filter value";//where attribute_name is the attribute for which you want the default value in the filter search field
    if(isset($_GET['Bills'])){
        $model->attributes = $_GET['Bills'];
    }

    $this->render('admin',array('model'=>$model));
}

这篇关于页面加载时的 CGridview 过滤器,在搜索字段中使用预定义值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆