onSQLSummaryValuesQuery Event

Description

Fires when the Grid has to compute summary values. Only fires if one or more columns in the Grid has summary values.

Discussion

If you have turned on summary values for any of the columns in the Grid, then this event will fire when Alpha Anywhere needs to compute the summary values to display in the Grid. Your event handler can take over the responsibility for computing these summary values.

If your Grid is based on a stored procedure, and your Grid displays summary values, then you must write code for this event to compute the summary values.

For example, say that your Grid has a column called 'Quantity' and you are displaying the count and average for this column.

Here is a sample event handler you might create:

function onSQLSummaryValuesQuery as v (e as p)

    dim flag as L
    flag = e.cn.execute("exec mySummaryValuesStoredProcedure @city = :whatcity",e.arguments)

    if flag = .t. then
        dim rs as SQL::ResultSet
        rs = e.cn.resultSet
        e.summary.Quantity.average = rs.data(1)
        e.summary.Quantity.count = rs.data(2)
        e.handled = .t.
    else
        e.fatalError = .t.
        e.errorText = "Could not get summary values." + e.cn.callResult.text
    end if 

end function

Event Arguments & Properties 

The following variables are available to you in the event:

Variable
Description
e.tmpl

The grid component definition

e.rtc

Run-time calculations (allows you to pass data to other event handlers)

e.__si

State information

e.cn

The SQL::Connection object for the Grid. You can call this object's .execute() method to execute your own SQL.

e.filter

The WHERE clause based on any filter that the user has applied to the Grid

e.sql

The SQL Statement that Alpha Anywhere has computed. If e.handled is not set to .t., then the Grid will combine this statement with the user filter (e.filter) to compute the summary values.

e.arguments

The SQL::Arguments object that contains values for all of the arguments in e.filter. To read a value from arguments: e.arguments.find("argumentName").data

e.summaryVariablesToBeComputed

A list of the summary values that need to be computed. The list contains a crlf delimited list of variable names whose values need to be set.

Your event must set the following properties:

Property
Description
e.handled

set to .t. if your event has computed the record count. set to .f. if you want Alpha Anywhere to execute its own count query

e.summary

The 'summary' properties of the 'e' object as explained below

The e.summaryVariablesToBeComputed contains a crlf delimited list of summary values that must be computed. For example, e.summaryVariablesToBeComputed might contain:

e.summary.Quantity.total
e.summary.Quantity.count
e.summary.Price.average

Your code would then need to set the value of each of these variables. For example:

e.summary.Quantity.total = 23
e.summary.Quantity.count = 3
e.summary.Price.average = 4.5

Your event can optionally set these properties of the e object:

Property
Description
e.fatalError

Set to .t. if a fatal error has occurred

e.errorText

The error text to show if a fatal error occurred

Example 

For example,

Setting State Variables 

You can also set state variables in this event. The value of any state variables will be available in all subsequent ajax callbacks (in the e.__si2 object).

To set a state variable:

e._state.myvar1 = "value1"
e._state.myvar2 = "value2"