Select All Checkboxes on a DataGrid in a QPanel
Mon, 11/02/2009 - 13:07
Hello Good People,
After reading the example on how to render checkboxes in a datagrid, I have successfully implemented such but the task I find a little bit difficult now is this:
I have a select all button. This button is suppose to select all the checkboxes rendered on the screen (Not all on record, just the one on that datagrid page rendered). How do i achieve this? Thanks in anticipation.
Cheers All!

Take a look at the code at http://examples.qcu.be/assets/_core/php/examples/datagrid/links_images.php. It has the following snippet to create a button control in the datagrid:
public function renderButton(Person $objPerson) {$objControlId = "editButton" . $objPerson->Id;
if (!$objControl = $this->GetControl($objControlId)) {
$objControl = new QButton($this, $objControlId);
}
Note that each button is created with a known ID... You can just iterate through the set of known ID's, do a $this->GetControl() on that ID, and get an array of QCheckBox objects as a result. Then you can just set the checked property to true on each, in a loop. Let me know if that makes sense.
Thought I already had this up, but couldn't find it.
Check out http://trac.qcu.be/projects/qcubed/ticket/364 for a nice way to get checkbox columns, including "Select All". :)
Try using some jQuery (:
if your select all checkbox is something like $chkSelectAll, and DataGrid $dtgDataGrid, you could use code as follows:
$this->chkSelectAll->AddAction(new QClickEvent(), new QJavaScriptAction(sprintf("$('#%s input:checkbox').val(this.checked)", $this->dtgDataGrid->ControlId)));
My ticket was designed to work with 1.0 as well, which didn't include jQuery.
hehe... of course... but jQuery is so cute... I just had to post it (:
Hey guyz! You both got wonderful ideas!
I've used both. I used VexedPanda's to implement select all when the header checkbox is selected and dugokontov's to select all if a button at the bottom of the list is clicked! You're both wonderful! Cheers!
I really wish cakePHP had an open forum like Qcubed (the google group isn't any inch close, pin in a hyastack)!
You're a bunch called: FAMILY!!!
Hey dugokontov, I got a $ not defined error and of course I know what that mean!
Is jQuery not included in qcubed 1.0.1? I actually search the js assets folder but found nothing like that? What you think?
In 1.0.1. there is no jQuery library included... I include them manually in header.inc.
It's also important to note that QCubed will never support the $ syntax in jQuery, so that it stays compatible with other frameworks. Always use the jQuery() function instead.
I should also note that my QCheckBoxColumn is not well suited to persistant selections.
eg: It's only good when the default state is that everything is unchecked.
Once you want to start checking boxes on initialize, it gets inefficient, and if you want to store just changes (so as to not affect the "checked" state of pages never displayed) it gets downright ugly.
Ok, new version up that deals with these things in a much more efficient manner. Should be pretty good, though any suggestions are welcome. :)
http://trac.qcu.be/projects/qcubed/ticket/364