Jump to content
Sign in to follow this  
jarto

TW3StringGrid is available

Recommended Posts

A new update is available in the development-channel of SmartUpdate. It contains a completely new Grid: TW3StringGrid. It's a completely new design, which was made to be very fast and able to handle lots of data. This is achieved through dynamic drawing: Only the visible grid lines are rendered.

There is a new StringGrid-demo in the Featured Demos. It downloads a json file and populates the grid with data from it.

TW3StringGrid supports six different column types:

  • Text (column class TW3StringGridTextColumn)
  • Numeric (column class  TW3StringGridNumericColumn)
  • EditBox (column class TW3StringGridEditColumn)
  • ComboBox (column class TW3StringGridComboColumn)
  • Checkmark (column class TW3StringGridCheckmarkColumn)
  • Button (column class TW3StringGridButtonColumn)

Columns are created by calling:

MyNewColumn:=Grid.AddColumn(ColumnClass);

If no ColumnClass is given, a Text column is created.

Column properties:

  • Caption
  • Width
  • BorderType
    • Default is btLightBorderRight. Set to btNone if you don't want any vertical borders.
  • Backgroundtype
    • Default is btNone to let the line color through.
  • AlignText (The same way as in TW3Label)
    • taLeft (default)
    • taCenter
    • taRight
  • SelectOptions (for TW3StringGridComboColumn only)
    • This is an array of selectable values. First value (index 0) is the value for no selection. For example: SelectOptions:=['','First','Second','Third'];
  • RowBorderType:
    • Default is btLightBorderBottom. Set to btNone if you don't want any horizontal borders.
  • RowBackgroundType:
    • Default is bsListItemBackground. Set to bsDecorativeListItemBackground (or test other backgrounds) to change the background style for even rows.
  • RowOddBorderType:
    • Default is btLightBorderBottom. Set to btNone if you don't want any horizontal borders. Affects odd rows.
  • RowOddBackgroundType:
    • Default is bsListItemBackground. Set to bsDecorativeListItemBackground (or test other backgrounds) to change the background style for odd rows.

Grid properties:

  • RowCount: Set number of rows to show
  • FixedColumns: How many columns should be fixed (aka not scrollable horizontally)
  • LineHeight
  • MultiSelect

Events:

  • OnCellClick: Is triggered when the row is clicked.
  • OnCellChanged: Is triggered when cell content changes through editing (for example: through editing)

Methods:

  • InvalidateGrid: Triggers a repaint of the grid.
  • Sort

Sorting

TW3StringGrid supports sorting based on one of multiple columns. Clicking on the column headers sets or reverses sort order. You can also control sorting in code:

procedure AddSortColumn(Index: Integer; SortOrder: TW3SortOrder = soNormal); overload;
procedure AddSortColumn(Col: TW3StringGridColumn; SortOrder: TW3SortOrder = soNormal); overload;
procedure SetSortColumn(Index: Integer; SortOrder: TW3SortOrder = soNormal); overload;
procedure SetSortColumn(Col: TW3StringGridColumn; SortOrder: TW3SortOrder = soNormal); overload;
procedure ToggleSortColumn(Index: Integer);

For example:

Grid.SortOptions.AddSortColumn(3,soReverse); //Set primary sort column
Grid.SortOptions.AddSortColumn(1); //Add secondary sort columns
Grid.Sort;

Working with sorted data

When the Grid is sorted, it only affects how data is shown. Sorting does not change Grid data itself at all. When you work with a sorted grid events and indexes (for example SelectedIndex) always refer to the index in the grid data itself and NOT the visible line number.

TW3StringGrid uses these events:

TW3StringGridColumnEvent = procedure(const Sender: TW3StringGridColumn; const Row: Integer);
TW3StringGridEvent = procedure(const Sender: TObject; const Row, Col: Integer);

If you have a Grid where "Australia" is on line 2, SelectedIndex:=2 selects that row regardless of how the grid is sorted. Clicking on that row or changing data on that row also returns Row=2 regardless of how the grid is sorted.

Share this post


Link to post
Share on other sites

I have just done a light review of this StringGrid demo and was wondering if TW3Button is an option. What the real question is how to get the unique ID of selected row and then take the user to either a new form or view based on the selected item.

At this time, I have used the TW3Grid, but was interested in perhaps switching over to this one.

Share this post


Link to post
Share on other sites
15 hours ago, Tim Koscielski said:

I have just done a light review of this StringGrid demo and was wondering if TW3Button is an option. What the real question is how to get the unique ID of selected row and then take the user to either a new form or view based on the selected item.

At this time, I have used the TW3Grid, but was interested in perhaps switching over to this one.

Sure, I can add a Button column type too. Also OnCellChanged will be added in the next update.

I've also been working on sorting. As the data is dynamically drawn, it's actually surprisingly easy to add. The trickiest is just to decide how the sorting interface should be done (properties etc.) so that I don't unnecessarily restrict future features. For example, in many Delphi grids there are quite detailed possibilities to control sorting.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×