About Data Aware Grids
Data aware grids provide a flexible control for displaying and editing database data in a grid format.
Data aware grids are based on the cDbCJGrid, cDbCJGridDataSource, and cDbCJGridColumn classes. The cDbCJGrid class extends the cCJGrid class by adding data-awareness. The main extensions are:
-
The object is a DEO object and supports the full DEO-DataDictionary interface convention. Changes made in the grid are reflected in the DataDictionary and your database. Changes made to the DataDictionary are reflected in your grid.
-
The
cDbCJGridColumnobjects are bound to a table and column. -
It provides support for DataDictionary enabled saving, editing, deleting, and validating of rows.
-
It provides automatic loading of data rows.
For a complete understanding of data aware grids, you should also read the section on Simple Grids.
Data Source
A cDbCJGrid uses a datasource object based on the cDbCJGridDataSource class. A grid's datasource object is created when the data aware grid object is created. The phoDataSource grid property provides a handle to the datasource.
With data aware grids (cDbCJGrid), the datasource is connected to a data dictionary object structure (via the grid's Server property) and automatically pages rows in and out of the datasource as required. This row caching makes it possible to scale up to very large databases.
In addition to loading data, the datasource is responsible for saving and deleting data. This includes validating the data and saving it to the database. It does this by interacting with the data dictionaries.
The datasource uses the grid columns to perform some of its tasks. For example, when a row is validated for a save, the datasource will send a message to each grid column asking it to validate its data.
Data Binding
The data aware cDbCJGridColumn allows you to bind a column to a table.column value in your data dictionary. You do this with the Entry_Item command (e.g., Entry_Item Customer.Name). This command sets two binding properties in the column object, piBindingTable and piBindingColumn.
The data binding, along with the data dictionary assigned in the cDBGrid class's Server property, is used to load data into the datasource and perform all of the data entry tasks defined by that column's data dictionary. This includes:
-
Setting the column's data type (peDataType).
-
Setting the column's data mask (psMask).
-
Column OnEntering, OnExiting, and OnValidating events.
-
Prompted lookups (Prompt_Object), etc.
See the cDbCJGridColumn class reference for more information about services provided by column data binding.
For information about setting data dictionary column properties in the Studio, see Data Dictionary Column Properties.
It is also possible to utilize data aware cDbCJGridColumn objects without a data binding. In this case, the column data is returned by the column's OnSetCalculatedValue function. This is the technique used to support Calculated Columns.
Vertical Scrolling
Data aware grids do not require that all the data is loaded at one time. By default, data is partially loaded and can be cached in and out of the datasource. This provides good performance with large data sets; however, a partially loaded dataset cannot provide enough information to render the grid's vertical scrollbar accurately.
In order to render an accurate vertical scrollbar, the grid needs to know:
-
The total number of rows in the entire dataset. This is used to calculate the size of the scroll thumb.
-
The position of the datasource's SelectedRow relative to the total number of rows in the dataset. This determines the accurate position of the scroll thumb.
With small datasets, the vertical scrollbar will always be accurate as the number of rows loaded into the datasource fits entirely within its cache. In this case, the datasource can provide all of the necessary information to render the vertical scrollbar accurately.
With large datasets, the vertical scrollbar is rendered according to the best information that the datasource is able to provide. As more data is paged into the datasource, this information becomes more accurate, and the vertical scrollbar's thumb is resized and repositioned. This effect is evident when using a data aware grid with a large dataset and you begin to scroll down pages of rows or attempt to jump to the last row.
If the data aware grid uses a "static" datasource, then all of the grid's data is loaded at once and no caching occurs. This technique does not scale well for large datasets, but the vertical scrollbar will always be rendered accurately. To specify a static datasource, set the grid's pbStaticData property to true. For more information, see Dynamic vs. Static Data.