I’m trying to use a CCheckBoxColumn in a gridview which allows multiple selections (Yii 1.1.2).
Checking individual checkboxes in the column will update that row and add the “selected” class to it’s css as expected.
The selected rows can then be viewed using
$.fn.yiiGridView.getSelection('container-id')
However checking the top checkbox in the header of the table doesn’t work as expected - it does successfully check all the boxes however it doesn’t update the individual rows and add the “selected” class. You can infact then uncheck a row and it will toggle that rows class to be selected even though the row itself is un-checked.
Specifically, the expected behaviour is that if you load the page and tick the checkbox in the header the following should happen:
All checkboxes in the CCheckBoxColumn should be checked.
All rows should be updated to have the "selected" class added.
Running $.fn.yiiGridView.getSelection(‘container-id’) should return all the checked rows.
Currently this is just because of a jQuery (let’s say) bug… that the row gets selected when clicking on the checkbox… because the TR.click event is fired even if a checkbox is clicked…
To understand what I mean… try to click in the checkbox column but not on the checkbox… click on the small space between the checkbox and the column border… you will get the row selected… so as it is currently this is not even a functionality programmed on the checkbox…
Even more on this… if the checkbox by default is selected… then unselecting that checkbox… the row will get selected… always because of the same bug…
And the getSelection() function returns selected rows… not checked rows… so I’m planning to add the getChecked() function…
go to the file CCheckBoxColumn.php inside the folder framework\zii\widgets\grid
And then go to init function.
You are going to see that the function for the “select all” checkbox only CHECKS all the checkboxes, but it doesn’t add the class SELECTED. The getSelected function seeks for the checkboxes that have the class “selected”, so that javascript function had to be corrected. The solution, then, is to add this lines to that function (I’m talking about line 130 in version 1.1.6:
This wonderful solution is from Issue 1394, in code.google.com
Another method is to change the getSelected function so it can check for the “checked” property instead of the “selected” class, but I haven’t found where to change this yet.
I hope this saves a lot of time, because it seems it isn’t still added for new Yii versions.