Skip to content

Fixed Columns are here! Freeze those columns!

Compare
Choose a tag to compare
@pavankataria pavankataria released this 19 Jun 04:25
· 26 commits to master since this release

Summary:

  • You can now have fixed columns on both left and right hand sides! It's as easy as either specifying the fixedColumns property in the configuration object, or by implementing the fixedColumns delegate method.

Technical:

  • Due to objective-c delegate requirements the type you return in the fixedColumns delegate method is a class instead of Swift's struct type.
  • Tests have been added to ensure the new DataTableFixedColumnType initialises as expected.
  • The leftColumn and rightColumn arguments in the initialiser are one-index based. That is they start at 1. This is to create a natural declaration of the fixed columns. For example, DataTableFixedColumnType.init(leftColumns: 2, rightColumns: 2) would fix the first 2 columns (from the left) and the last 2 columns (from the right).
  • As usual the delegate method will take priority. So the fixedColumns object will first be fetched from the delegate method and if it's not implemented it will fallback on the configuration object. So if you want the fixedColumn configuration value to be read then you need to make sure to omit the fixedColumns delegate method.

In practise

How to use the new Fixed columns feature!

Here's how you define which columns you want frozen, by using the all new DataTableFixedColumnType class, and using any of the initialisers like so

// Example 1 - freeze from the left
DataTableFixedColumnType(leftColumns: 1) // this will freeze the n number of columns from the left of the table. In this case column number 1 - the first columns. This is a one-index based system

// Example 2 .- freeze from the right
DataTableFixedColumnType(rightColumns: 1) // this will freeze n number of columns from the right of the table. In this case the last column. 

// Example 3 - multiple columns
DataTableFixedColumnType(leftColumns: 2, rightColumns1) // You can specify multiple columns to be frozen on both sides. In this case the first 2 columns and the last column.

You can implement fixed columns in your data table in two ways:

Via Delegate method

Simply adopt the SwiftDataTable's delegate method with the following signature:

@objc optional func fixedColumns(for dataTable: SwiftDataTable) -> DataTableFixedColumnType {
    // and return the object here
    return .init(leftColumn: 2) // freeze the first two columns
}

Via Configuration

var configuration = DataTableConfiguration()
configuration.fixedColumns = .init(leftColumns: 2, rightColumns: 1) // freeze both the first two columns, and the last column