Hi there, maybe not the perfect solution or best practice but it works for me.
I used the jQuery function .val() to update a hidden form field with the key values from the CGridView.
Unfortunately it doesn’t pass it to the controller as an array, but as a comma separated string , but in my case I will just explode it to an array on the server side.
To get the key values from the CGridView I used the following javascript:
$.fn.yiiGridView.getSelection(id)
which returns an array of key values of the currently selected rows of the grid, where the id parameter specifies the id of the grid.
To make it happen automatically you can use the the CGridView’s selectionChanged property to run some JavaScript. The javascript function you specify in the selectionChanged property runs whenever a row is selected or deselected.
/* The form that will be submitted */
echo CHtml::beginForm(array('someaction'),'post');
echo CHtml::hiddenField('your_field_name',null,array('id'=>'your_field_ID'));
echo CHtml::submitButton();
echo CHtml::endForm();
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'some-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'selectableRows'=>10,
'selectionChanged'=>'js:function(id) { $("#your_field_ID").val( $.fn.yiiGridView.getSelection(id) ); }',
'columns'=>array(
'Number',
'Date',
'Description',
),
));
jogasa21: I noticed you used var_dump, if you haven’t checked it out yet
CVarDumper::dump($var, $depth, $highlight)
is great. set the $highlight param to true and you get a nice human-readable var_dump