rtLib — Notes Rich Text Management Library Documentation of rtLib — Notes Rich Text Management Library Download rtLib — Notes Rich Text Management Library FAQ of rtLib — Notes Rich Text Management Library Purchase rtLib — Notes Rich Text Management Library Feedback about rtLib — Notes Rich Text Management Library

Cookbook

Table Sort

Start search Mail feedback Back to Description


rtTable

addNewLine (rtContainer) addNewLine (rTextParagraph) Collection (rtContainer) Collection (rtEnumeration) Columns ColumnSpacing getRichTextItem hasMoreElements NextElement sort

Code fragment from sample "Table Sort"; see full running samples in downloadable help.
Call ctxDump.getRichTextItem(doc,"Body")
' let's read the RichText of Body field
' some declarations
Dim coll As rtCollection, table As rtTable
Dim o As Variant
Dim keys(1), order(1), alpha(1)' arrays that contain directions for sort - may be simple variants True/False instead of arrays - see bellow
Dim headerRows As Integer' number of header rows (not sorted)
Dim sortEmptyBehind As Variant' true if empty colums sort at the end (in case of asc order)

Set coll = ctxDump.Collection (PARSE_GROUP_TABLE)
keys(0) = 2' first by second column
keys(1) = 3' then by first
alpha(0)=True' 1st key alphabetic
alpha(1)=False' 2nd key numeric
order(0)=True' ascending
order(1) = False' descending
headerRows = 1 ' number of header rows
sortEmptyBehind = False' empty rows first

Set enum = New rtEnumeration(coll)
Do While enum.hasMoreElements
Set table = enum.nextElement
table.columnSpacing = ONE_CM*0.5
Call table.sort(keys, alpha, order,headerRows,sortEmptyBehind)
Loop

' in fact the same may be done without arrays if we want to sort a single column (or parameters for several columns are the same)
' now - re-sort them in reverse order by ID
' comment this block out - then fancy multi-column sorting will show
%REM
Set enum = New rtEnumeration(coll)
Do While enum.hasMoreElements
Set table = enum.nextElement
Call table.sort(1, false, false,1,false)
Loop
%END REM
ctxDump.addNewLine 1