-
-
Notifications
You must be signed in to change notification settings - Fork 70
🥶 How to freeze columns
Pavan Kataria edited this page Jul 9, 2019
·
2 revisions
- You can now have fixed columns on both left and right hand sides! It's as easy as either specifying the
fixedColumnsproperty in the configuration object, or by implementing thefixedColumnsdelegate method.
- Due to objective-c delegate requirements the type you return in the
fixedColumnsdelegate method is a class instead of Swift's struct type. - Tests have been added to ensure the new
DataTableFixedColumnTypeinitialises as expected. - The
leftColumnandrightColumnarguments 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.
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:
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
}var configuration = DataTableConfiguration()
configuration.fixedColumns = .init(leftColumns: 2, rightColumns: 1) // freeze both the first two columns, and the last column