CGridView - focus on new row after adding

Hello,

Firstly, sorry for my English, I’m not native English speaker.

Secondly, how can I set focus on specific row in CGridView after adding new record to DB and redirecting user to page with CGridView.

I have this code in my action NewAction:


        if (isset($_POST['Libraries']) && is_array($_POST['Libraries'])) {

            $this->client->attributes = $_POST['Libraries'];

            if ($this->client->save()) {

                Yii::app()->request->redirect(Yii::app()->createUrl('clients/default'), true);

            }

        }

Code is redirecting to IndexAction.

Regards.

You could call grid view and pass the index of row grid to highlight.

Then you could create css code to change color to highlighted row.

For example:




        if (isset($_POST['Libraries']) && is_array($_POST['Libraries'])) {

            $this->client->attributes = $_POST['Libraries'];

            if ($this->client->save()) {

                Yii::app()->request->redirect(Yii::app()->createUrl('grid', array('row_position' => 10), true);

            }

        }



and in the grid view:




$rowPosition = Yii::app()->request->getParam('row_position', 0);


Yii::app()->clientScript->registerCss('css_row_position', <<< EOT_CSS_HIGHLIGHT    

    $('div#tablegrid tbody tr:nth({$rowPosition})').css('backgroundColor', '#00FF00');

EOT_CSS_HIGHLIGHT   

);



Thanks for advice, but problem is that, I don’t know what the index will have a new item. This should be based on ID of element (which is unique) and then CGridView should add css class “selected” to that element.

But I think I give up this idea, because now I see a new problem. When there will be more elements that limit per page, I should redirect, after adding new item, to page with that item, but I don’t know how to do this with a CGridView. So, now I have 2 big problems.