CGridView selected rows

Hi,

as someone in another topic said, “I did my best to search for answers but didn’t find the a solution”.

First, I am newbie in Yii.

I have 2 frames, the 1st has a CGridView component that print data from MySql tables. My goal is when I click on a row in CGridView, let I know in the 2nd frame which rows where selected.

I have the CGridView with multiple selection, the frames, and read that selectionChanged is a “a javascript function that will be invoked after the row selection is changed. The function signature is function(id) where ‘id’ refers to the ID of the grid view. In this function, you may use $.fn.yiiGridView.getSelection(id) to get the key values of the currently selected rows.”

My problem is, I don’t know how to use selectionChanged function.

Thank you for any help,

Markus

Hi,




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

	'id'=>'myGrid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'ID',

		...

	),

	'selectionChanged'=>'function(id){ your js code here, you can use $.fn.yiiGridView.getSelection(id) }',

)); ?>



I hope it helps you.

Thank you!

Yes, it works perfectly!

I use like this:




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

	'id'=>'myGrid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'ID',

		...

	),

	'selectionChanged'=>'userClicks',

)); ?>


<script type="text/javascript">

function userClicks(target_id) {

	alert($.fn.yiiGridView.getSelection(target_id));

}

</script>



It returs all selected rows, separated with commas in an array.

Later i thought it is not the correct way that javascript code is in view layer, but it looks like it is the only way.

Thanks!

Hi,

I have CGridView with where the ‘selectableRows’ property is ‘2’, so more rows can be selected. The $.fn.yiiGridView.getSelection(target_id) returs a list with the selected ids, but - and this is my problem - it is ASC-ordered. But I need to know the last id that user clicked. How can I get it?

I tried to search the answer for this question, but i didn’t find it. Please, if someone know, reply. Thank you

Canadian

Store the clicks in an array based on javascript and then store in the form element.

After it is submitted, get it back.