Hi,
Recently I have been trying to modify the CGridView to act as a form for tabular input. Since CGridView doesn’t support input components I decided to make my own column types to support select lists and text fields. This was all fine but when I added
'selectableRows' => 2
to the grid view a problem appeared.
Everytime I clicked the text field or select box to change the selection or to change the test the selection of the row was triggered. This was very annoying and caused serious usability issues. I was looking around for a hook in the grid view for changing this behaviour but there is nothing like a a way of telling a column if it shall be a part of the selection area for the row(not that I could find anyway).
In the CGridView the code for setting up the selectable area looks like this in the Javascript file jquery.yiigridview.js:
if (settings.selectableRows > 0) {
selectCheckedRows(this.id);
$(document).on('click', '#' + id + ' .' + settings.tableClass + ' > tbody > tr', function (e) {
var $currentGrid, $row, isRowSelected, $checks,
$target = $(e.target);
if ($target.closest('td').hasClass('button-column') || (e.target.type === 'checkbox' && !$target.hasClass('select-on-check'))) {
return;
}
As you can see this problem has already been addressed for the button-column feature. So by adding the class button-column to my new columns I got get rid of the problem like this.
array(
'name'=>'pricingAction',
'class'=>'SelectBoxColumn',
'htmlOptions'=>array('class'=>'button-column'),
'columnContent' => array('submit_change'=>'Submit','reject_change'=>'Reject'),
),
This is quite a dirty hack and can easily cause other problems but for now it does the trick.
If not I would like to suggest to add a new property called something like $excludeFromSelectionArea to the Grid view columns. This way this could be specified when adding the columns to the grid.
Something like this:
array(
'name'=>'pricingAction',
'class'=>'TextBoxColumn',
'excludeFromSelectionArea' => true,
),
Does anybody in the community know of a better way of doing this?