简体   繁体   中英

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. 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. in this request in $_REQUEST I have:

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. I know that I should do it through a parameter in CActiveDataProvider when I am creating the dataProvider but I can not find it.

Thanks in advance.

UPDATE 24 Jan
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;

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:

$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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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