页面加载时的 CGridview 过滤器,在搜索字段中使用预定义值

编程入门 行业动态 更新时间:2024-10-23 08:34:48
本文介绍了页面加载时的 CGridview 过滤器,在搜索字段中使用预定义值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:41:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   过滤器   加载   页面   CGridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!