How get row from cridview button click event

Hi guys.

So, i have a CButtonColumn on cgridview and need get the row selected when this button will clicked. I did this:




var test = $.fn.yiiGridView.getSelection(\'ponto_grid\');



But this only works if a row was selected.

How can i programmatically set a row selection or which other manner i could reach this objetive.

I need get the row selected to pass to my dialog to update information.

Thank you!


If you check the HTML rendered by Yii, you’ll notice that the CButtonColumn cells (including the <th> header) all have the class “button-column”.

Technically the button link is a child of a <td> element, so you may try with this

var column = $(".button-column");


Thank you very much again dude!

Ok, it´s returning the index of each row, how can i get the entire row with this index?

Thanks again!

Welcome man! Now you have to drill down again into the DOM. For instance:

column = $(".button-column"); // I dropped the var, not needed

clickedButtonIndex = column.index($(this).parent()); // includes the <th>

parentRow = $("table.items tr").eq(clickedButtonIndex);

In my alert:


The result was:({0:#2=({}), length:1, prevObject:{length:3, prevObject:{0:#1=({}), context:#1#, length:1}, context:#1#, selector:"table.items tr", 0:({}), 1:#2#, 2:({})}, context:#1#, selector:"table.items tr.slice(1,2)"})

How can i get value of columns?

Hmm if you don’t actually need the row index into the table, my suggestions above are kind of worthless ;)

If what you need is values of some columns in the very same row where you clicked a button, it’s way easier:


[*]Out of convenience, I’d recommend adding HTML classes to the columns that you want to fetch the value of. For instance, in your CGridView columns:

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











[*]Then you simply go up two levels in the DOM (td cell, then tr row), and then down one level (td with desired class)

fetchedValue = $(this).parent().parent().children(".someClass").text();


It worked!

God bless you dude!

Thank you very much.