This tutorial describes how to delete a row from a table in a Formspider Application. The tutorial continues from the “Regions” application built in the “How to create a new row” tutorial.
In this tutorial you will add a Delete button to the application which will be used to remove rows from the “REGIONS” table.
Open the “Regions” application in Formspider IDE. Open the “topPanel” in the Editor. Add a newbutton labeled “Delete Region”.
<panel> <tableLayout> <row> <cell> <button label="New Region"> <events> <buttonPress action="createRegion"/> </events> </button> </cell> <cell> <button label="Delete Region"/> </cell> </row> </tableLayout> </panel>
Using your favorite PL/SQL Editor, connect to the “HR” schema if you are using Formspider in a local installation or to your Online Schema if you are using Formspider Online, and open the “regions_pkg package”, created in the previous example. Add a new procedure to the package and name it “deleteRegion”. Call the “api_datasource.deleteCurrentRow” API to remove the current row from the “REGIONS1″ datasource.
Make sure that you expose the procedure in the package specification.
procedure deleteRegion is begin -- just to be sure that a row has been selected if api_datasource.getCurrentRowID('REGIONS1') is not null then api_datasource.deleteCurrentRow('REGIONS1'); end if; end;
In the Formspider IDE create an action called “deleteRegion” that calls the “regions_pkg.deleteRegion” procedure.
Edit the “topPanel” and add a buttonPress event to the button with the label “Delete Region” which executes the “deleteRegion” action.
<panel> <tableLayout> <row> <cell> <button label="New Region"> <events> <buttonPress action="createRegion"/> </events> </button> </cell> <cell> <button label="Delete Region"> <events> <buttonPress action="deleteRegion"/> </events> </button> </cell> </row> </tableLayout> </panel>
Click “Save” and run the application. To delete a region, click on a row that shows the region you would like to delete. Since the grid is bound to the “REGIONS1″ datasource, selecting a row in thegrid will automatically set that row as the current row of the “REGIONS1″ datasource. Then click “Delete Region” button. Note that the region you selected is removed from the grid. Since there is not a “Save” button in the application, this deletion will not be commited to the database.