我正在使用 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'=>'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()." ".CHtml::link($xcel.' Export to excel', array('ExcelAll'))."</div><br />{items}{summary}<div class=\"pager-fix\">{pager}</div>",));
该值出现在搜索字段中,我的 cgridview 正常工作,没有任何问题,但我无法触发 cgridview 刷新或过滤。有谁知道在使用预定义值加载页面后由谁触发 cgridview 进行过滤?
非常感谢任何帮助,如果您需要更多信息,请告诉我。
谢谢。
最佳答案
您可以在不修改任何客户端代码的情况下解决问题。在您的 Controller 操作中,只需设置属性的默认值,如下所示
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));
}
关于yii - 页面加载时的 CGridview 过滤器在搜索字段中具有预定义值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10539216/