Bug Correction for the CheckboxColumn

Hey, guys. Maybe some of you have noticed that the next bug:

You invoke the <code>$.fn.yiiGridView.getSelection(id)</code> function in ajax for a gridview, and notice that when the gridview’s “selectableRows” property has the value 2 (for multiselection), when having a checkboxColumn and clicking the “select all” checkbox, when you use the above mentioned function, the “getSelection” function, it returns nothing, which is of course a bug.

When I was about to correct this on my own code, I found the solution in Issue 1394, in code.google.com

The solution for this is pretty simple:

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:

if(checked) { //CMT added 2010-07-09

$(this).closest(‘tr’).addClass(‘selected’); //CMT added 2010-07-09

} else { //CMT added 2010-07-09

$(this).closest(‘tr’).removeClass(‘selected’); //CMT added 2010-07-09

} //CMT added 2010-07-09

});

)

Another method is to change the getSelected function so it can check for the “checked” property instead of the “selected” class, but I still haven’t found where to change this.

I hope this saves you a lot of time, because it seems it isn’t still added for new Yii versions. These lines I mentioned are very important to add: you don’t want you to happen the same that occurred to me, that I was showing a Yii-based program to my customers, when this bug occurred. They simply laughed.

Best regards, and many thanks once again for this marvelous framework.

David López Salgado.

Bogotá, Colombia.

Investigación y Programación

Note that this is already solved in the SVN trunk… and that the CCheckBoxColumn has changed since the release of Yii 1.1.6…