Select All Checkboxes on a DataGrid in a QPanel

Login or register to post comments
11 replies [Last post]
profnotime's picture
Offline
Joined: 01/13/2009

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!

alex94040's picture
Offline
Joined: 11/06/2008

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.

Offline
Joined: 03/31/2008

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". :)

Offline
Joined: 09/11/2009

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)));

Offline
Joined: 03/31/2008

My ticket was designed to work with 1.0 as well, which didn't include jQuery.

Offline
Joined: 09/11/2009

hehe... of course... but jQuery is so cute... I just had to post it (:

profnotime's picture
Offline
Joined: 01/13/2009

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!!!

profnotime's picture
Offline
Joined: 01/13/2009

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?

Offline
Joined: 09/11/2009

In 1.0.1. there is no jQuery library included... I include them manually in header.inc.

Offline
Joined: 03/31/2008

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.

Offline
Joined: 03/31/2008

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.

Offline
Joined: 03/31/2008

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