yii cgridview how to get it id

i have gridview in view


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

    'id'=>'goods-grid',

............



how can i get in this view id of this grid(goods-grid) to use it in js? like $this->grid->id

Accessing the id via $this->grid->id is not possible cause it is php and not javascript syntax.

You could use jquery to get the id of the grid like




// javascript

var grid = $("goods-grid"); // the grid itself

var gridId = grid.attr('id'); // the id of the grid => goods-grid

...






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

	'id' => 'goods-grid',

));






And when you need the id:




<?php echo $grid->id ?>



$this->grid->id its for example. i want to set grid id one time, and then access to grid-object, i guess it possible

for ex.

///js

var grid = $(’<?php echo $this->object_grid->id; ?>’);

may be more- how can i access to this grid in controller? dynamical set props, or only static props in view possible? :)

thx, but here main problem of question

i got js func, to update grid by ajax. i defined it before grid

<?php


$js_approve =<<<EOD

function() {

    $.fn.yiiGridView.update('{$grid->id}', {

            type:'POST',

            url:$(this).attr('href'),

            success:function(data) {

                    $.fn.yiiGridView.update('{$grid->id}');

            },

    });

    return false;

}

EOD;

then i define grid


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

    'id'=>'goods-grid',

.............

array(

            'class'=>'CButtonColumn',

            'buttons'=>array(

                'update'=>array(

                    'label'=>Catalog2Module::t('Approve'),

                    'imageUrl'=>'',

                    'url'=>'Yii::app()->controller->createUrl("approve", array("id"=>$data->primaryKey))',

                    'click'=>$js_approve,

so the problem -i need first define grid with ‘click’=>$js_approve but $js_approve not works because of no grid defined

so only way it’s using manual id of grid?

Defined at grid level, thus did you try $this->id ?

/Tommy

May I suggest


$(this).closest('.grid-view').attr('id')

Regards