DataSource - cCJGridDataSource
Returns the entire datasource as a tDataSourceRow array
Type: Function
Return Data Type: tDataSourceRow[]
Syntax
Function DataSource Returns tDataSourceRow[]
Call Example
Get DataSource to tDataSourceRow[]Variable
Description
DataSource returns the entire contents of the current datasource data as a tDataSourceRow array. You use this to process data in a static cCJGrid grid.
You will rarely use this with dynamic data aware grids (cDbCJGrid) since the cDbCJGridDataSource class maintains and updates the DataDictionary data for you.
Sample
In this example, the cCJGrid gets data from the datasource object and processes it by sending the custom message UpdateMyDataRow for each row of data.
Procedure ProcessGridData
Handle hoDataSource
tDataSourceRow[] TheData
Integer iRows i
Get phoDataSource to hoDataSource
Get DataSource of hoDataSource to TheData
Move (SizeOfArray(TheData)) to iRows
For i from 0 to (iRows-1)
Send UpdateMyDataRow TheData[i]
Loop
End_Procedure
If you need to perform some kind of process on all rows in a grid, it is usually best to work directly with the DataSource array and then reload the grid. Working directly with the array is faster than updating individual values in the grid. If you are working with large amounts of data, the speed difference could be significant.
Sample
This example takes the datasource and removes all items with a status value that is not equal to "N". (Presumably a checkbox column in the grid represents this status value.) After creating a new datasource, the grid is reinitialized using the cCJGrid object's InitializeData method. This procedure would be added to your cCJGrid object.
Procedure RemoveInactive
Handle hoDataSource
tDataSourceRow[] TheData TheNewData
Boolean bFound
Integer iRows iNewRows i iStatus
Get piColumnId of oCustomer_Status to iStatus
Get phoDataSource to hoDataSource
Get DataSource of hoDataSource to TheData
Move (SizeOfArray(TheData)) to iRows
For i from 0 to (iRows-1)
If (TheData[i].sValue[iStatus]="Y") Begin
Move TheData[i] to TheNewData[iNewRows]
Increment iNewRows
End
Loop
Send InitializeData TheNewData
Send MovetoFirstRow
End_Procedure
If your processing of the data does not include any changes in the number of rows or the ordering of your data and you wish to refresh your grid such that the current row and column is maintained with the same offset from the grid top, you can do this by saving and restoring the selected row (SelectedRow / MoveToRow), selected column (SelectedColumnObject / MoveToColumnObject) and the offset from the top (ComTopRowIndex). This example in a cCJGrid object sets all values in a column to "N", which will presumably clear all checkboxes in this column.
Procedure SetAllInactive
Handle hoDataSource hoSelCol
tDataSourceRow[] TheData
Integer iRows i iSelectedRow iTopOffset iStatus
Boolean bFound bOk
Get piColumnId of oCustomer_Status to iStatus
// Get the current selected row, column and the offset from the top.
Get SelectedRow of hoDataSource to iSelectedRow
Get SelectedColumnObject to hoSelCol
Get ComTopRowIndex to iTopOffset
// update the data
Get phoDataSource to hoDataSource
Get DataSource of hoDataSource to TheData
Move (SizeOfArray(TheData)) to iRows
For i from 0 to (iRows-1)
Move "N" to TheData[i].sValue[iStatus]
Loop
Send InitializeData TheData
// restore row, column and offset
If (iSelectedRow<>-1) Begin
Send MoveToRow iSelectedRow True
If hoSelCol Begin
Get MoveToColumnObject hoSelCol to bOk
End
Set ComTopRowIndex to iTopOffset
End
End_Procedure
Return Value
Returns the contents of the datasource in a tDataSourceRow array.