Interface

SortableTableDataSource

Sortable Table Data Source


Description

Lets a TableDataSource sort its own rows.

Implement it in addition to TableDataSource and clicking a sortable column header asks the source to sort instead of sorting inside the table - the table has no copy of the data to sort. After sorting, the table redraws and asks for the cells again.

Methods

Name

Parameters

Returns

Shared

SortByColumn

column As Integer, ascending As Boolean

Integer()

Method descriptions


SortableTableDataSource.SortByColumn

SortByColumn(column As Integer, ascending As Boolean) As Integer()

Reorder the visible projection and return a permutation. The permutation tells the table which row each position came from, so it can carry selection, row heights and tags over to the new order.

This example sorts a list of indices, reorders the records by it and returns it:

' Sort a list of indices, then reorder the records by it
Var order() As Integer

For i As Integer = 0 To mRows.LastIndex
  order.Add(i)
Next

' A key array sorted together with the indices: the indices follow the keys
Var keys() As String

For Each i As Integer In order
  keys.Add(CellTextAt(i, column))
Next

keys.SortWith(order)

If direction = DesktopTable.SortDirections.Descending Then
  Var flipped() As Integer

  For i As Integer = order.LastIndex DownTo 0
    flipped.Add(order(i))
  Next

  order = flipped
End If

Var sorted() As Record

For Each i As Integer In order
  sorted.Add(mRows(i))
Next

mRows = sorted

' The permutation lets the table carry selection, row heights and tags over
Return order

Compatibility

Project Types

Desktop

Operating Systems

All