Consultor Eletrônico



Kbase 18638: Apptivity - Computed Value Data Object as Grid Column
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   3/25/1999
Applies to Apptivity Developer and Runtime, 2.1 and above.

SUMMARY:

Often there is a need to include on each row of a data bound
abGridView control, a calculated value based on the value of another
column in that row of the grid's Data Source.

Creating a Data Object which returns a computed value, and binding a
grid column to the Data Object (covered separately in the Apptivity
Developer's Guide) may seem the natural way to implement this, but
additional code is needed to correctly calculate the value for each
row. Otherwise, the Data Object's value will be calculated based on
the current row, and this value will be repeated on each row of the
grid.

SOLUTION:

1) The simplest solution is to include the calculated value as
one of the columns returned by the query, that is, do the
calculation in the SELECT statement. This may not be possible
in all cases.

2) The code below illustrates an alternative implementation, using
a Data Object. It uses the Suppliers table of the Northwind
database. This is the source code for a computed value Data
Object, which calculates an integer value for each row of the
data bound grid, based on the SupplierID column of the Suppliers
table. This is a very simplified case, intended for
illustration only.

class cvlInteger extends abCalculator
{
public Object recalc ( abEnv theApp )
{
Integer retVal = null; //Initialize retVal here
//Add your code here
abColumn sID = null;
sID = theApp.getColumn ("ds_Sup", "SupplierID");
for (int i = m_beginRange; i<= m_endRange; i++)
{
retVal = doCalc(sID, i);
try {
recordComputedValue(retVal, i);
}
catch (Exception e) {e.printStackTrace();}
}

allRowsComputed();
//End of your code
return retVal;
}

private Integer doCalc (abColumn s_ID, int rowNumber)
{
Integer cur_ID = null;
Integer new_ID = null;
try {
cur_ID = new Integer (s_ID.getValue(rowNumber).toString());
new_ID = new Integer (cur_ID.intValue() + 1);
}
catch (Exception e) {e.printStackTrace();}
return new_ID;
}
}


References To Written Documentation:

Progress Knowledge Base Solutions:
17651, "Apptivity: Display Calculated Database Fields in Grid"
18701, "Apptivity - How to Calculate Value in Grid Column on Event
Apptivity Developer's Guide