Get value from CGridView

I need to perform a javascript function call when one of the row items is selected but I need some of the data from the row as a parameter.

So far I have this as the CGridView populated with all the data:




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

	'id'=>'data-grid',

	'dataProvider'=>$dataProvider,

	'selectionChanged'=>"function(id){alert($.fn.yiiGridView.getSelection(id));}",

	'columns'=>array(

		'identifier',

		'name',

		// more columns...

	),

)); ?>



This will give me a popup with the row number, but how can I retrieve the data from one of the columns? Instead of alert(), I have some js function that needs the identifier for that row.

Is doing this directly in the javascript selectionChanged() function possible? Do I need an ajax action of some type to do this instead?

Note that per current implementation $.fn.yiiGridView.getSelection(id) returns an array of primary keys of the selected rows not the row numbers

I have problem on this ‘selectionChanged’=>“function(id){alert($.fn.yiiGridView.getSelection(id));}”,

I click one give me pk value. And Same row click again alert null value. Then click again it give me pk value. Why is it always give me pk value?

$.fn.yiiGridView.getSelection(); returns PK of selected rows…

So if you click first time a row… this row gets selected and you get the PK in the alert…

The second time you click on the same row… that row gets unselected… and that’s why you get null…

…so how can i disabled same row click "selected remove"? or is there anyway to get pk value ?

I did not completely understand your question… but I presume you need a PK value of any row you click…

For that you can add a column with the PK value (if you don’t want it visible set it as hidden) then with jQuery you can read the value of that column for the clicked row

Simple to say, hard to make for me. I understand your said. But i dont have enough knowledge to read that pk value column.

Here is a solution I gave for a similar situation where the first column value is read - http://www.yiiframework.com/forum/index.php?/topic/13804-dynamic-deleteconfirmation-in-the-cbuttoncolumn/page__view__findpost__p__68407

ok thank you for helps. I’ll try