$.fn.yiigridview.getchecked Returns Empty Values


I am trying to get a column value of selected row of Cgridview

'selectionChanged' => 'myFunction',

function myFunction() {

$.fn.yiiGridView.getChecked("my-grid-id", "column-id"))


but getChecked returns an empty array, why ?

I check the javascript code of yii (jquery.yiigridview.js) And I found

getChecked: function (column_id) {


this.find('.' + settings.tableClass).children('tbody').children('tr').children('td').children('input[name="' + column_id + '"]').each(function (i) {




why inputp[name=… ??

In CGridView there is no Input in the rows except header of CGridView, so thats why returns empty array, how exactly works ?

I think it works only with rows that has checkbox html…

In this case how to get the columns value of selected row ?

like that (getCurrentValue is fake function name)

$.fn.yiiGridView.getCurrentValue("my-grid-id", "column-id");

Many thanks

You got it:

[size=“2”][color="#222222"][font=“monospace”]$(gridID).yiiGridView(‘getSelection’) - should be used to get selected rows[/font][/color]

[color="#222222"][font=“monospace”]$(gridID).yiiGridView(‘getChecked’, columnID) - should be used to get checked rows[/font][/color]

[color="#222222"][font="monospace"]Corresponding documentations:[/font][/color][/size]



Thanks Domba for the quickly response!

$(gridID).yiiGridView(‘getSelection’) returns the key-id of the selected row,

but how to get a specific column value by its id ?

(especially if the id is not displayed on CGridView)

You get the PK of that row regardless if the ID is shown or not, so in the backend you can do a findByPk() to get any value you want.

I want to use the value of cell of the selected row directly in javascript.

Your solution is the best only if a new request will be happened to get anything you want from the web-server.

So I wrote a javascript to do that

   function clickedToRow(target_id) {

        var head = $('#' + target_id + " tr #my-id");

        var idx = $('#' + target_id + " thead tr th").index(head);

        $('#' + target_id).find('tr.selected').each(

                function() {

                    var cell = $(this).children().eq(idx);





What do you think ?

Can this comment be useful to you ? http://www.yiiframework.com/forum/index.php/topic/13804-dynamic-deleteconfirmation-in-the-cbuttoncolumn/page__view__findpost__p__72358

Also, check the whole thread for similar ideas.

Yes, it is another way but could be usefull,

In addition using

var head = $('#' + target_id + " tr #my-id");

var idx = $('#' + target_id + " thead tr th").index(head);

in your post make id more dynamic because detects the column id ;)

So if later the order of columns changed, developer no worry about the :nth-child(2) should be :nth-child(5)

Thanks Domba :)