sasori
sasori

Reputation: 5455

how to keep selected filter option dropdown selected after CGridView update in Yii 1.1.14?

One of the filter options in my CGridView in Yii 1.1.14, has this

        array(
            'header' => 'Status',
            'name' => 'status',
            'filter' => CHtml::dropDownList('MyModel[status]','status', array(
                    '' => '',
                    '0' => 'Approved',
                    '1' => 'Pending',
                    '2' => 'Rejected'
            )),
            'type' => 'raw',
            'value' => 'MyHelper::model()->getStatus($data->status)',
            'htmlOptions' => array('width' => '8%')
        ),

My problem is, whenever I select one from the dropdown filter, the CGridView updates the result which is right, but then the selected option from the dropdown disappears, I mean it doesn't remain selected. How to keep it selected?

Upvotes: 1

Views: 577

Answers (2)

Onkar
Onkar

Reputation: 49

Whenever your gridview reloads, firstly the call goes to you controller's action there you must have declared you model's variable/object, so in your controller's action you can set this variable to your model like this :

$myModel->status = $_GET['status'];

and when call returns to your view, there you can check for the value, that is set to that 'status' variable.

Upvotes: 0

Irfan Ali
Irfan Ali

Reputation: 2258

You have to pass selected value to dropDownList. like below

  CHtml::dropDownList('MyModel[status]', MyModel->status, array(
                '' => '',
                '0' => 'Approved',
                '1' => 'Pending',
                '2' => 'Rejected'
        )),

I have given default Approved status. i.e second parameter of dropDownList function.

Upvotes: 2

Related Questions