Class: cDbCJGrid

Properties  Events  Methods    Index of Classes

Used to create data-aware multi-row, multi-column display and entry grids. This is a DataDictionary-enabled grid.

Hierarchy

cObject
---cUIObject
------DfComUIObject
---------DfInPlaceComObject
------------DfComActiveXControl
---------------cComActiveXControl
------------------cCJReportControl
---------------------cCJGrid
------------------------cDbCJGrid
---------------------------cDbCJGridPromptList

Library: Windows Application Class Library

Package: cDbCJGrid.pkg

Mixins: server_mixin verify_mixin

Description

The cDbCJGrid class extends the cCJGrid class by adding data-awareness. The cDbCJGrid class supports the complete Data-Entry-Object (DEO) interface and allows the grid to be used with DataDictionaries.

Each column in a grid is represented by a column object. The cDbCJGrid uses the cDbCJGridColumn class for its column objects. These grid column objects, which must be created by the developer, are nested inside of the cDbCJGrid.

Data is stored and maintained in a datasource object. The cDbCJGrid uses a cDbCJGridDataSource class for its datasource object. The cDbCJGrid object creates this object automatically.

A non-data-aware version of a grid is provided by the cCJGrid superclass. The cCJGrid uses a cCJGridColumn class for its column objects and a cCJGridDataSource for its datasource object.

A sub-class of the cDbCJGrid class, cDbCJGridPromptList provides support for data-aware selection lists.

The following provides a short introduction to cDbCJGrids. You should refer to Using Grids for a complete overview of the grid classes. The Class Reference will provide you with syntactical and usage information about the grid classes.

Working with cDbCJGrids


The cDbCJGrid extends the cCJGrid class. 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 cDbCJGridColumn objects are bound to a table and column. This binding is used to:
    o Handle data movement between the DEO grid and DataDictionary
    o Provide columns with automatic property settings (data type, mask, etc.) and events
        (validating, entering, exiting, etc.) from the DataDictionary.
- It provides support for DataDictionary enabled saving, editing, deleting and validating of rows
- It provides automatic loading of data rows.
    o This data adheres to the DataDictionary constraints (find filters)
    o Data is loaded by a specified table index.
    o Supports loading the data, caching the data and removing data from the cache as needed

A data-aware grid will normally consist of a single cDbCJGrid object, an internally created cDbCJGridDataSource object and multiple cDbCJGridColumn objects to define the grid. With data-aware grid columns, the table binding data provides the information to set up the column. This makes the grid column object code simple. The data is loaded and ordered based on the Server and Ordering properties.

Object oOrderDtl_Grid is a cDbCJGrid
    Set Server to OrderDtl_DD
    Set Ordering to 1
    Set Size to 63 377
    Set Location to 90 3
    Set peAnchors to anAll
    Set pbAllowInsertRow to False
    Set pbRestoreLayout to True
    Set psLayoutSection to "OrderView_oOrderDtl_Grid1"
    Set piLayoutBuild to 6
    Set pbHeaderPrompts to True
    
    Object oMark is a cCJGridColumnRowIndicator
    End_Object
    
    Object oInvt_Item_ID is a cDbCJGridColumn
        Entry_Item Invt.Item_ID
        Set piWidth to 91
        Set psCaption to "Item ID"
        Set psImage to "ActionPrompt.ico"
    End_Object

    Object oInvt_Description is a cDbCJGridColumn
        Entry_Item Invt.Description
        Set piWidth to 213
        Set psCaption to "Description"
    End_Object

    Object oInvt_Unit_Price is a cDbCJGridColumn
        Entry_Item Invt.Unit_Price
        Set piWidth to 53
        Set psCaption to "Unit Price"
    End_Object

    Object oOrderDtl_Qty_Ordered is a cDbCJGridColumn
        Entry_Item OrderDtl.Qty_Ordered
        Set piWidth to 50
        Set psCaption to "Quantity"
    End_Object

    Object oOrderDtl_Price is a cDbCJGridColumn
        Entry_Item OrderDtl.Price
        Set piWidth to 62
        Set psCaption to "Price"
    End_Object

    Object oOrderDtl_Extended_Price is a cDbCJGridColumn
        Entry_Item OrderDtl.Extended_Price
        Set piWidth to 81
        Set psCaption to "Total"
    End_Object
    
End_Object


Dynamic and Static Data


By default, cDbCJGrids are dynamic. The data is loaded as needed and it is cached in and out as needed. If you wish, you can declare your data to be static by setting the pbStaticData property. When you do this, the data can still be loaded automatically, but the entire set of data will be loaded once upon activation. In addition, you could choose to manually load the data yourself using InitializeData. This allows you to provide filters that cannot be easily applied using constraints. Static data is fully editable and all edits will be properly processed through the DataDictionary objects (DDOs).

When the data is static and read only, you can choose to either use the cCJGrid or the cDbCJGrid class for this purpose. Even though you are working with database data, you actually might find it easier to use the simpler cCJGrid class. Don't always assume that grids that display database data must use the cDbCJGrid class.

Examples


Sample

This sample shows how to export data from a cDbCJGrid to a file. You can add this code to the oOrderDetail_Grid object in Order.vw in the Order Entry sample workspace to export data from the current order detail line items in the grid to a .CSV file.

Procedure Export
   Handle hoDataSource hoWorkspace hoColumn
   Integer iGridColumns iGridColumn iRows iRow iElements iElement iChannel eDataType iDecSeparator 
   String sOrderNumber sFileName sFolder sValue sValueSeparator

   Get phoDataSource to hoDataSource
   Move (Seq_New_Channel ()) to iChannel
   If (iChannel >= DF_SEQ_CHANNEL_MIN) Begin
       Get RowCount of hoDataSource to iRows
       Get ColumnCount to iGridColumns
       If (iGridColumns > 0) Begin
           // Create filename and open output channel
           Get Field_Current_Value of oOrderDetailDataDictionary Field OrderDetail.Order_Number to sOrderNumber
           Get phoWorkspace of ghoApplication to hoWorkspace
           Get psHome of hoWorkspace to sFolder
           If (Right (sFolder, 1) <> SysConf (SYSCONF_DIR_SEPARATOR)) Begin
               Move (sFolder + SysConf (SYSCONF_DIR_SEPARATOR)) to sFolder
           End
           Move (sFolder - sOrderNumber - '.csv') to sFileName
           Direct_Output channel iChannel sFileName

           Get_Attribute DF_DECIMAL_SEPARATOR to iDecSeparator
           If (iDecSeparator = Ascii (',')) Begin
               Move ';' to sValueSeparator
           End
           Else Begin
               Move ',' to sValueSeparator
           End

           Decrement iGridColumns
           Decrement iRows

           For iRow from 0 to iRows
               For iGridColumn from 0 to iGridColumns
                   Get ColumnObject iGridColumn to hoColumn
                   Get RowValue of hoColumn iRow to sValue
                   Get peDataType of hoColumn to eDataType
                   If (eDataType = Ascii_Window) Begin
                       Write channel iChannel '"' sValue '"'
                   End
                   Else Begin
                       Write channel iChannel sValue
                   End
                   If (iGridColumn < iGridColumns) Begin
                       Write channel iChannel sValueSeparator
                   End
               Loop
               Writeln channel iChannel
           Loop

           Close_Output channel iChannel
       End

       Send Seq_Release_Channel iChannel
   End
End_Procedure


There are a number of samples of the cCJGrid class, as well as the cDbCJGrid class, in the Grids.src program in Specialized Components workspace.