The Towns Tab

The Towns tab demonstrates how you can use Scope objects to easily convert search UI input into a query. A Scope object is basically a narrowly defined search condition that you can add to a SQL Query object. When a SQL Query object queries the database it will combine all scopes that have been added to it and create the WHERE clause of the query.

Overview

On the Towns tab you can search for towns. You can enter two different search criteria. The first is a search on town names and accepts a string (1). The second allows you to filter towns by a specific department (2). Clicking the Search button displays the results (3). Clicking on a result displays the department the town is in and a custom table property that is defined in the Tables Behavior button script (4).

The search field accepts boolean searches. In this example towns with names containing "agen" or "amb" will be returned as long as they are in the "Lot" department.

Note: All of the scripts that shown in this lesson are in the group "TownsGroup" script.

Searching For Towns Using Scopes

With Scope objects you can easily create dynamic searches. Here is how:

1) Create a SQL Query object using the table you are targeting. You can only add Scope objects that were created for this table. The object is stored in the array variable theQueryA.

2) Determine which Scope objects to add to the SQL Query object. When you add a Scope to a SQL Query you pass in a value to insert into the Scope conditions. Remember that the conditions for both of the scopes we created in the previous lesson had a binding variable (:1). The binding variable will be replaced with the parameter(s) you pass in.

3) Tell the SQL Query to retrieve the data from the database and to store it as an array in the variable theTownsA.

4) Assign the array variable theTownsA to a Data Grid.

0 Comments

Add your comment

E-Mail me when someone replies to this comment