Kbase P41400: How to re-sort a SmartDataBrowsers after a row update
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/16/2008 |
|
Status: Unverified
GOAL:
How to re-sort a SmartDataBrowser after a row update
GOAL:
How to re-sort an updateable SmartDataBrowser after a row update
FIX:
There are two ways to re-sort the query in the SmartDataBtowser:
- Re-open the query with DYNAMIC-FUNCTION('open-query').
This way is faster and more simple to program, but it is not recommended in Web Client or slow networks because the records are reading from the data base again.
- Re-sort the RowObject temp-table in the 'submitRow' function.
The following program is an example with a SDO sorted by 'NAME' field. This program is an example and should be changed according to your application requirements:
FUNCTION submitRow RETURNS LOGICAL
( INPUT pcRowIdent AS CHARACTER,
INPUT pcValueList AS CHARACTER) :
DEFINE VARIABLE hDataHandle AS HANDLE NO-UNDO.
DEFINE VARIABLE hDataSource AS HANDLE NO-UNDO.
DEFINE VARIABLE iRowsToBatch AS INTEGER NO-UNDO.
DEFINE VARIABLE iRowsReturned AS INTEGER NO-UNDO.
DEFINE VARIABLE cRowID AS CHARACTER NO-UNDO.
DEFINE VARIABLE lResult AS LOGICAL NO-UNDO.
DEFINE VARIABLE iPosition AS INTEGER NO-UNDO.
DEFINE VARIABLE cValue AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFirstValue AS CHARACTER NO-UNDO.
DEFINE VARIABLE cLastValue AS CHARACTER NO-UNDO.
/*Get the field 'name' position in pcValueList parameter*/
ASSIGN iPosition = LOOKUP('name':U, pcValueList, CHR(1)).
{get DataHandle hDataHandle}.
/*If field 'name' is in the pcValueList parameter means that the field 'name' value was changed, therefore the query should be re-sorted*/
IF iPosition GT 0
THEN DO:
ASSIGN cValue = ENTRY(iPosition + 1, pcValueList, CHR(1))
lresult = SUPER( INPUT pcRowIdent, INPUT pcValueList )
iRowsToBatch = DYNAMIC-FUNCTION('getRowsToBatch':U).
/*Get the first and last field 'name' value*/
FIND FIRST RowObject NO-LOCK NO-ERROR.
IF AVAILABLE RowObject
THEN ASSIGN cFirstValue = RowObject.NAME. ELSE ASSIGN cFirstValue = "".
FIND LAST RowObject NO-LOCK NO-ERROR.
IF AVAILABLE RowObject
THEN ASSIGN cLastValue = RowObject.NAME. ELSE ASSIGN cLastValue = "zzzz".
/*If the new value (cValue) still in the RowObject Temp-table just the RowObject temp-table will be re-sorted*/
IF cValue GE cFirstValue AND cValue LE cLastValue
THEN DO:
hDataHandle:QUERY-CLOSE.
hDataHandle:QUERY-PREPARE("FOR EACH RowObject BY name INDEXED-REPOSITION").
hDataHandle:QUERY-OPEN.
hDataHandle:REPOSITION-TO-ROWID(TO-ROWID(ENTRY(1,pcRowIdent))) NO-ERROR.
END.
/*If the new value (cValue) is not in the RowObject temp-table, the Dataset with the new value will be loaded in RowObject temp-table*/
ELSE DO:
ASSIGN cRowID = DYNAMIC-FUNCTION('firstRowIds':U, INPUT "FOR EACH customer NO-LOCK").
RUN sendRows
(?,
cRowID, /* RowIdent specified to repos to */
true,
1,
OUTPUT iRowsReturned).
ASSIGN cRowID = DYNAMIC-FUNCTION('firstRowIds':U, INPUT "FOR EACH customer WHERE customer.name = '" + cValue + "' NO-LOCK").
RUN sendRows
(?,
cRowID, /* RowIdent specified to repos to */
FALSE,
iRowsToBatch,
OUTPUT iRowsReturned).
END.
END. /*IF iPosition GT 0*/
RETURN lResult.
END FUNCTION.