BBjStandardGrid::setColumnSortedByRelatedData

Description

In BBj 6.0 and higher, this BBjStandardGrid method specifies whether a particular column is to be sorted by relatedData rather than by the text of the cells.

Syntax

Return Value

Method

void

setColumnSortedByRelatedData(int columnIndex, boolean p_sortByRelated)

Parameters

Variable

Description

columnIndex

Specifies the zero-based index on which to sort.

p_sortByRelated

Indicates whether data should be sorted by related data.

Return Value

None.

Remarks

A column is always in one of three states:

  • Unsorted
  • SortedByText)
  • SortedByRelatedData

Calling sortByRelatedData( A, TRUE ) causes column A to assume the state of SortedByRelatedData and to be immediately sorted by related data. If column A is in the state SortedByRelatedData then calling sortByRelatedData( A, FALSE ) causes column A to assume the state of Unsorted.

If column B is in the state Unsorted then calling sortByColumn(B, sortOrder) will cause column B to assume the state SortedByText. But if column B is in the state SortedByRelatedData then calling SortByColumn(B, sortOrder) does not change the state of column B.

Special care should be taken when using this method if sortByMultipleColumns is FALSE since changing the sortByRelatedData value for one column causes that column to be sorted which in turn causes all other columns to assume the state of Unsorted.  In particular consider the following sequence of commands:

0990  grid!.setSortByMultipleColumns( 0 )
1000  grid!.sortByRelatedData( A, 1 )
1010  escape
1020  grid!.sortByColumn( A, grid!.SORT_DESCENDING )
1030  escape
1040  grid!.sortByRelatedData( B, 1 )
1050  escape
1060  grid!.sortByColumn( A grid!.SORT_DESCENDING)
1070  escape

Here is a breakdown of how this example performs:

Line

Sorts the Grid

1010

In ascending order by the relatedData of column A

1030

In descending order by the relatedData of column A

1050

In ascending order by the relatedData of column B and column A will be unsorted

1070

In descending order by the text value of column A

Note: The grid is sorted by RelatedData at line 1010 but is sorted by text data at line 1070 because column A became unsorted after executing line 1040.  

Example

rem 'is column user sortable

rem 'Obtain the instance of the BBjAPI object
let myAPI!=BBjAPI()

rem 'Open the SysGui device
SYSGUI=UNT
OPEN (SYSGUI) "X0"

rem 'Obtain the instance of the BBjSysGui object
let mySysGui!=myAPI!.getSysGui()

rem 'Set addWindow param values
X=10
Y=10
WIDTH=300
HEIGHT=300
TITLE$="BBj Window - Sort"

rem 'Set the current context
mySysGui!.setContext(0)

rem 'Create a window
myWindow! = mySysGui!.addWindow(X,Y,WIDTH,HEIGHT,TITLE$,$000002$)

rem 'Add a grid on the window
myGrid! = myWindow!.addGrid(101,25,25,250,200,$8060$,10,2)

rem 'Add button to the window
sortButton!=myWindow!.addButton(102,90,230,120,30,"Sort On Related Data",$$)

rem 'Set the grid properties
myGrid!.setFitToGrid(1)
myGrid!.setEditable(1)
myGrid!.setHasColumnHeader(1)

rem 'Create some data to fill the grid with
rem 'Spell out the first 10 Greek letters in English, and specify their
rem 'alphabetical order with related data.
dim alpha$[10]
dim relatedData[10]
alpha$[1]="Alpha"
relatedData[1]=1
alpha$[2]="Beta"
relatedData[2]=2
alpha$[3]="Delta"
relatedData[3]=4
alpha$[4]="Epsilon"
relatedData[4]=5
alpha$[5]="Eta"
relatedData[5]=7
alpha$[6]="Gamma"
relatedData[6]=3
alpha$[7]="Iota"
relatedData[7]=9
alpha$[8]="Kappa"
relatedData[8]=10
alpha$[9]="Theta"
relatedData[9]=8
alpha$[10]="Zeta"
relatedData[10]=6

rem 'Add text to the grid cells
FOR ROW = 0 TO 9
    rem 'Populate column 0 with names of Greek letters
    myGrid!.setCellData(ROW,0,alpha$[ROW+1],STR(relatedData[ROW+1]:"00"))
    myGrid!.setCellText(ROW,1,STR(ROW+1))
NEXT ROW

rem 'Set the text for the column header
myGrid!.setColumnHeaderCellText(0,"Sort")

rem 'Set the first column sortable based on related data by clicking on the
rem 'header
myGrid!.setColumnSortedByRelatedData(0,0)
myGrid!.setColumnUserSortable(0,1)
myGrid!.sortByColumn(0,1)

rem 'Register the CALLBACK routines
myGrid!.setCallback(myGrid!.ON_GRID_EDIT_STOP,"CALL_RESORT")
myWindow!.setCallback(myWindow!.ON_CLOSE,"APP_CLOSE")
sortButton!.setCallback(sortButton!.ON_BUTTON_PUSH,"SORT_OPTIONS")

rem 'Process Events
process_events

rem 'Callback routine called when the user closes the application window
APP_CLOSE:
release

CALL_RESORT:
    PRINT "calling resort"
    myGrid!.resort()
return

SORT_OPTIONS:
    if (myGrid!.isColumnSortedByRelatedData(0))
        myGrid!.setColumnSortedByRelatedData(0,0)
        sortButton!.setText("Sort on Related Data")
    else
        myGrid!.setColumnSortedByRelatedData(0,1)
        sortButton!.setText("Sort on Displayed Data")
    endif
    myGrid!.sortByColumn(0,1)
return

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.