logicpill
(Chargrove)
October 12, 2010, 10:45pm
1
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?
mdomba
(Maurizio Domba Cerin)
October 13, 2010, 7:09am
2
Note that per current implementation $.fn.yiiGridView.getSelection(id) returns an array of primary keys of the selected rows not the row numbers
alper
(Adoruatli)
December 21, 2010, 11:59am
3
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?
mdomba
(Maurizio Domba Cerin)
December 21, 2010, 12:05pm
4
$.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…
alper
(Adoruatli)
December 21, 2010, 12:15pm
5
…so how can i disabled same row click "selected remove"? or is there anyway to get pk value ?
mdomba
(Maurizio Domba Cerin)
December 21, 2010, 12:21pm
6
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
alper
(Adoruatli)
December 21, 2010, 12:33pm
7
Simple to say, hard to make for me. I understand your said. But i dont have enough knowledge to read that pk value column.
mdomba
(Maurizio Domba Cerin)
December 21, 2010, 12:36pm
8
alper
(Adoruatli)
December 21, 2010, 12:53pm
9
ok thank you for helps. I’ll try