Sorting Settings

The ITabCustomSort interface is used to work with objects in the table.

The example is given for setting of descending sorting by the C column in a regular report with the REPORT_TAB identifier. The report contains analytical data area.

As a result the table looks as follows:

Fore Example

To execute the example, add links to the Metabase, Report, Tab assemblies.

Sub TableView;
Var
    mb: IMetabase;
    Report: IPrxReport;
    Table: ITabSheet;
    CustomSort: ITabCustomSort;
    Sort: ITabCustomSortItem;
Begin
    // Get current repository
    mb := MetabaseClass.Active;
    // Get regular report
    Report := mb.ItemById("REPORT_TAB").Edit As IPrxReport;
    // Get table
    Table := (Report.ActiveSheet As IPrxTable).TabSheet;
    // Get sorting parameters
    CustomSort := Table.CustomSort;
    // Clear current sorting settings
    CustomSort.Clear;
    // Set sorting range
    CustomSort.Range := Table.Regions.Item(0).Range;
    // Set that sorting is made by the C column
    CustomSort.Add(Table.ColumnIndex("C"));
    // Set sorting parameters
    Sort := CustomSort.Item(0);
    // Determine that sorting is descending
    Sort.Direction := TabCustomSortDirection.Descending;
    // Set that numeric values are sorted
    Sort.Type := TabCustomSortType.Value;
    // Process sorting
    CustomSort.Sort;
    // Save changes
    (Report As IMetabaseObject).Save;
End Sub TableView;

Fore.NET Example

Imports Prognoz.Platform.Interop.Report;
Imports Prognoz.Platform.Interop.Tab;

Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    Report: IPrxReport;
    Table: ITabSheet;
    CustomSort: ITabCustomSort;
    Sort: ITabCustomSortItem;
Begin
    // Get current repository
    mb := Params.Metabase;
    // Get regular report
    Report := mb.ItemById["REPORT_TAB"].Edit() As IPrxReport;
    // Get table
    Table := (Report.ActiveSheet As IPrxTable).TabSheet;
    // Get sorting parameters
    CustomSort := Table.CustomSort;
    // Clear current sorting settings
    CustomSort.Clear();
    // Set sorting range
    CustomSort.Range := Table.Regions.Item[0].Range;
    // Set that sorting is made by the C column
    CustomSort.Add(Table.ColumnIndex["C"]);
    // Set sorting parameters
    Sort := CustomSort.Item[0];
    // Determine that sorting is descending
    Sort.Direction := TabCustomSortDirection.tcsdDescending;
    // Set that numeric values are sorted
    Sort.Type := TabCustomSortType.tcsValue;
    // Process sorting
    CustomSort.Sort();
    // Save changes
    (Report As IMetabaseObject).Save();
End Sub;

See also:

General Programming Principles Using the Tab Assembly