Custom Alternate View

The custom alternate Grid view allows you create expressions that will be processed from the data in the grid display and an Xbasic function to turn the arrays of expression values into an actual view. This is the infrastructure that allowed Alpha Software to turn a Google Map Component into a Google Map alternate view.

Before you define an alternate view, you need to know what you're defining. Once you've got your goal in mind, you can list the data you'll need to collect, and figure out how you'll process the data to display the alternate view. In many cases, you will want to use a predefined widget that has a JavaScript API, and you will generate the HTML to house the JavaScript widget as well as the JavaScript to add the collected data to the widget .

The first step in defining the alternate view to Alpha Anywhere is to check Has Alternate View in the grid properties.

The alternate view definition is a combination of one or more data expressions for collecting the data and an Xbasic function for processing the collected data.

Once you type in the name of the Xbasic function you want to use, the "Show function prototype" link will be enabled. Click on that link and Alpha Anywhere will generate a commented prototype function for you.

It is worthwhile reading the prototype function carefully so that you can understand the flow of data in the alternate view.

Click on the "Copy to clipboard" button, close the function prototype,

click on "Open Xbasic Function Declarations",

and paste your function. You can edit your Xbasic function to generate the required HTML and JavaScript for your view. It's a good idea to create sample data and a sample function call that you can use to test your function. When your function is working properly, you can comment out the sample data and sample function call.

You'll also have to create one or more data expressions. The next section explains why data expressions are necessary.

Navigate to the correct starting record in the query (for example, if the Grid is showing 20 records per page, and you navigate to page 3, the starting record will be record number 41).

Loop over the records in query, generating the HTML to show the Grid (This is called the 'Main Loop').

The loop continues until you have generated the desired number of rows (based in the 'Rows per page' property), or you reach the last record in the query.

While the Main Loop is executing, you can capture additional information from each record in the query.

The way in which you specify what additional information you want to capture is by specifying one or more expressions that should be evaluated in the Main Loop.

The expressions are evaluated, and the expression results are placed into arrays (called 'value arrays'). There will be one value array for each expression that you specify. Each value array will have one entry for each row that is displayed in the Grid. So, for example, if the Grid is set to display 20 rows per page, each array will have 20 entries.

Once the Main Loop has completed, the Xbasic function that you specified for the Alternate View is called and the value arrays are passed into the Xbasic function. The Xbasic function can then use the data in the value arrays to compute the HTML to display in the Alternate View.

When you specify the expressions that you want to evaluate, you can define several types of expressions:

Regular Xbasic expressions. Use this syntax to reference a field value in the query: tbl.data("fieldname")

Templates. The template is a text string that can include Xbasic expressions. For example: {tbl.data("fieldname")}. The data enclosed in the curly brackets can be any Xbasic expression.

Function. Specify the name of an Xbasic function that will return the value you want to capture. The function prototype will be: YourFunctionName (e)

Alternate View expressions are written in Xbasic. Your expression will typically need to reference field values from the Grid query. To reference a field value in the current Grid query, i.e. data from the row, use this syntax:

tbl.data("fieldname")

The field value that you read using the above syntax is correctly typed. For example, it will be a character, numeric, time, date, etc. value.

In most cases, a data expression or template is sufficient to capture the necessary information from the current record in the Grid query. However, there are situations where more control is needed over how the data from the current row is captured. An Xbasic function can be defined to create the data expression.

To use an Xbasic function, specify the name of the Xbasic function to call when defining the data expression:

The function must be defined in the Xbasic Function Declarations section for the Grid Component. The Function prototype link can be used to create a function prototype after you enter the function name in the text box. The function prototype can be copied and then pasted into the Xbasic Code section using the Open Xbasic Function Declarations link.

The function prototype takes a single argument, e (which is of type P). The e object contains a pointer to the tbl object, which can be used to access data in the table/result set for the current row in the Grid query.

The following example shows a custom Xbasic function to capture data from the current row in the Grid query: