Is there any way to cause an app variable to change, say from true to false, whenever a user has a checkbox selected that is part of an edit grid (using the widget settings "Checkbox row Selection" option) and also switch the variable back if they uncheck the box?
Announcement
Collapse
No announcement yet.
Using Edit Grid Checkbox Row Selection to change appvar
Collapse
X
-
We currently do not have a behavior tied to a grid for when it has checkbox selection turned on, and we will add this to our feature request list.
In the meantime, you can create an 'Execute Script' on startup via the behavior section to achieve this. Please make sure to name your widget.
Code:var testAppVar = getAppVar('testAppVar'), editGridWidget = getWidget('myEditGrid'); editGridWidget.down('grid').on('selectionchange', function (sm, selected) { if (!Valence.isEmpty(selected)) { setAppVar('testAppVar', true); } else { setAppVar('testAppVar', false); } }); success();
The code attaches an event handler to the 'selectionchange' event of the grid object which is a descendant of the object referenced by editGridWidget variable. The event handler takes two arguments, a selection model object (sm) and an array of selected records (selected).
The event handler checks if the selected array is not empty using the Valence.isEmpty function. If it's not empty, the code sets the testAppVar application-level variable to true by calling the setAppVar function. If it is empty, the testAppVar variable is set to false.
Comment