onSQLRefreshRowQuery Event

Description

Fires when the Grid needs to select the current row in the Grid to refresh it.

Discussion

Executes whenever the data in the current row of the Grid needs to be refreshed. Your event handler can take over the responsibility of returning a resultset that contains the data for the current Grid row.

If your Grid is based on a stored procedure you must write code for this event to return a resultset for the current Grid row. The primary key for the current Grid row will be passed into the event handler.

The 'e' object that is passed into the event handler contains the value of each primary key column for the current row.

For example, say that the primary key for the table that the Grid is based on is based on two columns. You can get the value of each primary key column using this code:

e.arguments[e.arguments.argumentNumber("PKValue_1")].data
e.arguments[e.arguments.argumentNumber("PKValue_2")].data

Here is a sample event handler your might create:

function onSQLRefreshRowQuery as v (e as p)

    dim flag as L
    flag = e.cn.execute("exec myRefreshRowStoredProcedure @pkvalue = :PKValue_1")
    if flag = .t. then 
        e.resultset = e.cn.resultSet
        e.handled = .t.
    else
        e.fatalError = .t.
        e.errorText = "Could not refresh row. " + 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.sql

The SQL Statement that Alpha Anywhere has computed to get the data to refresh the row.

e.arguments

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

e.arguments contains values for each column in the current record's Primary Key. For example if the Primary Key has 2 columns, then you can get the values for these columns as follows:

e.arguments[e.arguments.argumentNumber("pkvalue_1")].data  - value of first Primary Key column
e.arguments[e.arguments.argumentNumber("pkvalue_2")].data  - value of second Primary Key column

Your event must set the following properties:

Property
Description
e.handled

Set to .t. if your event has returned the resultset to use

e.resultset

A SQL::ResultSet of records to show in the Grid (need only be set if e.handled is set to .t.)

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

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"