简体   繁体   English

Yii1 CGridView(Yii-Booster):如何更改TbGridView中的过滤键(filterVal)(基于CGridView)?

[英]Yii1 CGridView(Yii-Booster): How to change filter key(filterVal) in TbGridView(based on CGridView)?

I am using yii-booster(4.0.1) TbGridView(extends CGridView) and need to change the filter variable name in _REQUEST($_POST, $_GET) for filter function. 我正在使用yii-booster(4.0.1)TbGridView(扩展CGridView)并需要更改_REQUEST($ _ POST,$ _GET)中的过滤器变量名称以获取过滤器功能。 In my grid, I have filter functionality and when I press enter after entering some words in the filter input, an ajax request will sent for server. 在我的网格中,我有过滤功能,当我在过滤器输入中输入一些单词后按Enter键时,将为服务器发送ajax请求。 in this request in $_REQUEST I have: 在$ _REQUEST的请求中我有:

array
(
    'page' => '1'
    'wsi_it_model_Asset' => array
    (
        'user' => 'eghlima'
        'createdAt' => ''
        'serial' => ''
        'brand' => ''
        'model' => ''
        'assetType' => ''
        'assigned' => ''
        'location' => ''
        'status' => ''
    )
)

My question is how can I change wsi_it_model_Asset in the request created by CGridView. 我的问题是如何在由CGridView创建的请求更改wsi_it_model_Asset。 I know that I should do it through a parameter in CActiveDataProvider when I am creating the dataProvider but I can not find it. 我知道我应该在创建dataProvider时通过CActiveDataProvider中的参数执行此操作,但我找不到它。

Thanks in advance. 提前致谢。

UPDATE 24 Jan 1月24日更新
I found my code from another project, as you can see I can change the key for sort and pagination , I need something look like for filtering key; 我从另一个项目中找到了我的代码,因为你可以看到我可以更改sortpaginationkey ,我需要看起来像过滤密钥;

return new \CActiveDataProvider($this->applicant, array(
            'criteria' => $criteria,
            'pagination' => array(
                'pageVar' => 'p', // <<<<< pagination var
                'pageSize' => 20,
            ),
            'sort' => array(
                'sortVar' => 's', // <<<<< sorting var
                'defaultOrder' => 't.firstName ASC',
                'attributes' => array(
                    '*'
                )

            ),
        ));

So for pagination, the request which is posting from client to server will be: 因此,对于分页,从客户端发布到服务器的请求将是:

array
(
    'p' => '7' // <<<<<< page changed to `p`
    'wsi_it_model_Asset' => array
    (
        'user' => 'eghlima'
        'createdAt' => ''
        'serial' => ''
        'brand' => ''
        'model' => ''
        'assetType' => ''
        'assigned' => ''
        'location' => ''
        'status' => ''
    )
)

Im not sure what you are meaning, but I give it a try. 我不确定你的意思,但我试一试。

$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'my-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        array(
            'value' => '$data->theValue',
            'filter' => CHtml::activeTextField($model, 'myWish'),
        ),
    )
));

And then in your model you add a virtual attribute 然后在您的模型中添加虚拟属性

public function getMyWish()
   {
      return 'Your dream answere';
   }

And in your $model->search() add: 并在你的$ model-> search()中添加:

$criteria->compare('$data->theValue', $this->myWish,true);

Something like this check a very good tutorial on virtual attributes: http://www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods/ 像这样的东西检查一个关于虚拟属性的非常好的教程: http//www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM