Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 4 Advanced Tasks : Creating Custom Add and Delete Buttons for a Grid Pane

Creating Custom Add and Delete Buttons for a Grid Pane
TIBCO Business Studio Forms will automatically create Add and Delete buttons for the records in a grid pane if you enable those options on the grid pane’s custom properties sheet. But in some cases, you may wish to provide custom logic to be executed when a record is added or deleted. To do this, you will customize the Add and Delete buttons.
Task
Customize the Add and Delete buttons for a grid pane.
Sample Project
To view the sample for this task, import the advanced sample projects as described in Import the Forms Advanced Samples. The sample form and business object model for the task described in this section are contained in the forms.samples.scripting sample project.
The form (CustomGridActions.form) is at the following location:
   forms.samples.scripting/Forms/GridPane/CustomGridActions/
The directions here assume that you already have a form with a grid pane that is bound to an array of objects of type forms.samples.scripting.GridRecord. In the sample, the GridRecord class is in the business object model FormsSamplesScripting.bom at the following location:
   forms.samples.scripting/Business Objects/
You can double-click the form and business object model filenames (as well as those of other project resources) in the Project Explorer to open them in the editor. There, you can examine their contents and use them as models for your own projects.
Explanation
To customize the Add and Delete buttons for the grid pane, perform these steps:
1.
In the Properties tab of the Properties view for the grid pane, make sure the Support Add Operation and Support Delete Operation check boxes are cleared.
2.
Add a shared script action named Add Record. Specify the following script for this action:
   var newRecord =    factory.forms_samples_scripting.createGridRecord();
   pane.grid.getValue().add(newRecord);
   pane.grid.setSelection(newRecord);
Use the following script for multi-select grid panes:
   var newRecord =    factory.forms_samples_scripting.createGridRecord();
   pane.grid.getValue().add(newRecord);
   pane.grid.getSelection().add(newRecord);
3.
Add a shared script action named Delete Record. Specify the following script for this action:
   var selection = pane.grid.getSelection();
   if (selection!=null) {
       var rc = confirm("Delete the current record?");
       if (rc==true) {
           var list = pane.grid.getValue();
           list.remove(selection);
       }
   }
Use the following script for multi-select grid panes:
   var selection = pane.grid.getSelection();
   if (selection!=null) {
        var rc = confirm("Delete the current record?");
       if (rc==true) {
           var list = pane.grid.getValue();
           for (var i=selection.size()-1; i>=0; i--) {
                var sel = selection.get(i);
                selection.remove(i);
                list.remove(sel);
           }
       }
   }
4.
The shared script actions and rules described here can be examined in the Properties view by clicking their names in the Outline view of the sample project’s CustomGridActions form:

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved