Skip to content

piSortColumn - cCJGrid

Determines which column is sorted

Type: Property
Access: Read/Write
Data Type: Integer
Parameters: None

Syntax

Property Integer piSortColumn
Access Type Syntax
Read Access: Get piSortColumn to IntegerVariable
Write Access: Set piSortColumn to IntegerVariable/Value

Description

piSortColumn determines which column is sorted. If pbShadeSortColumn is True, the sorted column identified by piSortColumn will be shaded. If piSortColumn is -1, the default, it means that no column is selected as the sort column.

piSortColumn is usually set when you click on a header to sort the data or change the ordering (in a cDbCJGrid). It is set inside of SortGridByColumn and ReorderGridByColumn (in cDbCJGrid). Note that setting this property does not change the sort order. Setting it to -1, does not change the order, it just determines which column is shaded. If you change this value, it is your responsibility to make sure it is the same as the grid's actual order.

piSortColumn and pbReverseOrdering are used differently with regular grids and data-aware grids. Normally, you will not need to use these properties in your grids, but if you do note the following differences.

cCJGrid Behavior

Any time a data is initialized or re-initialized by sending InitializeData, the piSortColumn is set to undefined (-1) and pbReverseOrdering is set to False. At this point, new data has been loaded in an unknown order and these values must be reset. If you, as the developer, know what this order is, you can set these properties yourself, immediately after sending InitializeData. It is your responsibility to set these to a sensible value based on your data. Setting these properties at any time other than following InitializeData is not recommended.

Because piSortColumn and pbReverseOrdering are reset when data is initialized, setting these properties before a grid is activated and initialized (i.e., setting them at design-time) serves no purpose.

Procedure LoadMyData
    tDataSourceRow[] DataSourceArray

    Move "Zap" to DataSourceArray[0].sValue[0]
    Move "1345" to DataSourceArray[0].sValue[1]

    Move "Yow" to DataSourceArray[1].sValue[0]
    Move "1345" to DataSourceArray[1].sValue[1]

    Move "Gasp" to DataSourceArray[2].sValue[0]
    Move "1345" to DataSourceArray[2].sValue[1]

    Move "Aha" to DataSourceArray[3].sValue[0]
    Move "1345" to DataSourceArray[2].sValue[1]

    Send InitializeData DataSourceArray
    // Since this data was created in reverse order based on the first column, we will
    //  these two properties as a visual clue.
   Set pbReverseOrdering to True
   Set piSortColumn to 0
End_Procedure

cDBCJGrid and cDbCJridPromptList Behavior

With data-aware grids, these properties might be static and can be set at design time. If your grid is dynamic, the ordering and direction of the data is determined by Ordering and pbReverseOrdering. A column may or may not be associated with the index ordering. If one is, you can set piSortColumn so that the column is visually distinguished. These properties can all be set at design time, although you should keep in mind that they may be changed as the grid is used. For example, if you support changing index ordering and direction by clicking on the header, all of these properties may be changed. If the grid is closed and activated again the property values will be whatever they were when the grid was deactivated and not values you set at design time. Often this behavior is desired as the grid will reactivate with the same characteristics it was closed with.

If you do need to make sure that your grid is re-activated with specific settings, you can set these properties while the grid is being created inside of the OnCreateGridControl event.

Procedure OnCreateGridControl
    Forward Send OnCreateGridControl
    // each time the grid is activated, we want the ordering to be 1, reversed and the
   // sort column designated as the third column.        
    Set Ordering to 1
    Set pbReverseOrdering to True
    Set piSortColumn to 2
End_Procedure

Use OnCreateGridControl and not Activating for this purpose.