yii cgridview how to get it id

i have gridview in view

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



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.


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


$js_approve =<<<EOD

function() {

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



            success:function(data) {




    return false;



then i define grid

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









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


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 ?


May I suggest