How To Get Grid Id From The Controller

Hi all,

I’m trying to open modal for viewing/editing single row data from a gridview, using yiiStrap (I think with bootstrap is the same).

This is the view:




$this->widget('zii.widgets.grid.CGridView', array(

    'id' => 'scadenza-grid',

    'dataProvider' => $model->search(),

    'filter' => NULL,

    'columns' => array(

        ...

        array(

            'class' => 'CButtonColumn',

            'template' => '{view} {update}',

            'buttons' => array(

                'view' => array(

                    'click' => 'js:function(id)

        {

            var x = document.getElementById("codice");

            x.value = $.fn.yiiGridView.getSelection("scadenza-grid");

        }',

                    'options' => array(

                        'data-toggle' => 'modal',

                        'data-target' => '#finestra',

                    ),

                ),

            ),

        ),

    ...

));


$this->widget('bootstrap.widgets.TbModal', array(

    'id' => 'finestra',

    'header' => 'Dettaglio scadenza',

    'remote' => Yii::app()->createUrl('scadenza/viewmod'),

    'footer' => array(

        TbHtml::button('chiudi', array('data-dismiss' => 'modal')),

    ),

));



And this is the controller:




    public function actionViewmod() {

        $selpk = Yii::app()->request->getQuery('id');

        $this->renderPartial('viewmod', array(

            'model' => $this->loadModel($selpk),

        ));

    }



The problem is that I need the grid id in the controller and cannot send it from the view as a parameter. I cannot parameterize the modal definition, because it’s created before of the user interaction; and the “url” option of the button is ignored.

Neither the "getQuery" in the first row of the action runs.

I tried to capture it in the "click" option of the button (as shown) and put it in an hidden field to be read later, with no success (may be this is for my lack in js/ajax).

Help me! Thx

Create / update with dialog

another Create update with dialog

you could use them or the second has how to get the id in the buttoncolumn

I already know these articles and have tried the quickdlgs extension. The quickdlgs really runs, but it’s heavy and not so maneageble. So I would like to substitute it with yiiStrap.

The grid id is needed in the controller, not in the buttoncolumn.

public function actionViewmod($id) {

    $selpk = Yii::app()->request->getQuery('id');


    $this->renderPartial('viewmod', array(


        'model' => $this->loadModel($selpk),


    ));


}

Notice the $id and in your URL for button do something like

'

In your button column

‘url’=>’$this->grid->controller->createUrl(“viewmod”, array(“id”=>$data->id))’’

Sorry if it’s a little jumbled I typed this on my phone

Also in any function the data you want to pass to it you can put in the ( ).

Sorry but I can’t understand what you’re saying.

This was my first attempt (it seems logical). But it doesn’t run because the “url” parameter in the button column definition is ignored when found a “remote” parameter in the modal definition. Furthermore this “remote” parameter can’t contains the id because it’s written in the page before the user choose the row from the grid.

That’s the reason why I need to read the id directly from the controller.

Well, I’ve found a solution here: wiki from Arockia Johnson