ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: TonyLeech on March 17, 2016, 01:50:30 am

Title: Refresh Checkbox row-select column
Post by: TonyLeech on March 17, 2016, 01:50:30 am
I have a multipage grid with a column of checkboxes for selecting the rows.  I have a header checkbox with that.

The header checkbox has been set to only select/unselect a page at a time.

After selection the user can change the filter/sort which changes the displayed rows.  The already checked/selected rows are afterwards sometimes on different pages so can be difficult to find and unselect.

So I have made a dialog box when the user 'unchecks' the header checkbox and in it I offer the choice to unselect ALL rows for entire grid, not only the visible page.  This clears the selections fully, but the checkboxes on other pages are still viewed as checked even though the row is properly unselected.  I thought that cb: select: linked the rows to the checkboxes for me...

                          cb: { header: true, all: false, select: true },

I use the following to unselect all rows with the dialog....

                  myGrid.on( "beforeCheck", function( event, ui ) {
                     if (ui.source=='header' && ui.check==false) {
                        $( "#dialog-uncheck" ).dialog({
                           resizable: false,
                           height:140,
                           modal: true,
                           buttons: {
                              "Page": function() {
                                 $( this ).dialog( "close" );
                                 $("#grid_php").pqGrid( "setSelection", {rowIndx:2} );    // this is a test and also doesn't activate row 2 checkbox
                                 $("#grid_php").pqGrid( "refreshColumn", {dataIndx: "state"} );     // this doesn't seem to refresh the checkboxes
                              },
                              "All": function() {
                                 $( this ).dialog( "close" );
                                 $("#grid_php").pqGrid( "setSelection", null );
                                 $("#grid_php").pqGrid( "refreshColumn", {dataIndx: "state"} );
                              },
                              Cancel: function() {
                                 $( this ).dialog( "close" );
                                 return false;
                              }
                           }
                        });
                     }
                       });


Can you recommend the correct way to refresh the checkbox view to match the selected/unselected rows?

Thank you in advance for your assistance.

Incidentally...still using v3.2.0 as I have a software deadline coming up and can't risk a full code update just yet.
Title: Re: Refresh Checkbox row-select column
Post by: paramvir on March 17, 2016, 11:32:37 pm
That makes sense but selection and checkbox are connected only when checkboxes are checked through the user interface.

In case of sorting and filtering along with checkbox selections, it would be simpler to keep it cb.all = true, otherwise you have keep the checkbox state consistent with the selections yourself.
Title: Re: Refresh Checkbox row-select column
Post by: TonyLeech on March 22, 2016, 06:23:12 pm
Thanks, how do I alter the checkbox state programatically?  I guess I could read the selection array before clearing the affected checkboxes.

Incidentally I did start with cb.all=true, but I found that I kept forgetting that all other pages were being selected and not just the 50 I was looking at (i.e. my page size was 50).

Alternatively can I change cb.all to true on-the-fly using 'beforeCheck' as the trigger? And then return it to cb.all = false afterwards?

Thanks again.

Tony
Title: Re: Refresh Checkbox row-select column
Post by: paramvir on March 23, 2016, 12:57:39 pm
You are right, selection array can be read to clear the corresponding checkboxes.

checkbox state can be altered with help of rowData[ dataIndx of checkbox field ].

Code: [Select]
beforeCheck: function( event, ui ) {
                if (ui.source=='header' && ui.check==false) {

var sel = this.selection({type: 'row', method: 'getSelection'}),
i = sel.length;
while( i-- ){
sel[i].rowData.state = false;
}
this.setSelection(null);
}
},


Changing cb.all at run time in beforeCheck event would leave the selections/ checkboxes in inconsistent state, so it can't be used this way.
Title: Re: Refresh Checkbox row-select column
Post by: TonyLeech on March 24, 2016, 07:46:37 pm
Excellent.  Thanks.  That worked.