Tutorial 7: How to delete a row

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>

Click “Save”

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.

Creating "deleteteRegion" action.

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.

Deleting row.

  • George

    The focus is lost when a row is deleted. Focus is available again only after clicking a rows in the grid.
    Similarly a newly created row do not get the focus which should be the default behavior.

    • http://www.gerger.co Yalim K. Gerger

      Hi George. Thanks for the feedback. I opened a ticket in our system regarding the issues you pointed out. I will update this thread when they are fixed.

      • George Rajan

        Thank you very much. This is real prompt reply.

    • İbrahim Sandallı

      Hi George. By default, the focus is lost when a row is deleted. However, it’s also possible to move the focus to the next or previous row using the “When current row is deleted” attribute of the datasource.

      To set this attribute, navigate to the Datasource Definitions tree from the Formspider IDE, find your datasource and double-click on this datasource to open its edit dialog. Note that the value “None” is selected in the “When current row is deleted” combobox, meaning that the focus will be lost when a row is deleted. To move the focus to the previous row, you can select “Move Up” option from this combobox. Similarly, you can select “Move Down” to move the focus to the next row.

      Unfortunately, there is no way to automatically focus to a new row. As Yalım mentioned, we will work on it and update the thread when it’s fixed.