A Swift Data Table package, display grid-like data sets in a nicely formatted table for iOS. Subclassing UICollectionView that allows ordering, and searching with extensible options.
Thanks for the support of the community and the PR submitted by @kaomte in https://github.com/pavankataria/SwiftDataTables/pull/60 we're able to get this released smoothly.
The package automatically enables this feature for you.
You can choose to opt out or opt in for certain data tables in two ways:
Simply adopt the SwiftDataTable's delegate method with the following signature:
func shouldSupportRightToLeftInterfaceDirection() -> Bool {
// and return true or false here. True will allow the data table to detect if a RTL language is being used and will flip the entire layout appropriately and display content correctly.
// false will leave the layout direction and only flip the text which would happen regardless anyway without this feature.
return true
}
var configuration = DataTableConfiguration()
// The default is true
configuration.shouldSupportRightToLeftInterfaceDirection: Bool = false // set to false incase you don't want to use this feature
fixedColumns
property in the configuration object, or by implementing the fixedColumns
delegate method.fixedColumns
delegate method is a class instead of Swift's struct type.DataTableFixedColumnType
initialises as expected.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).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
SwiftDataTableConfiguration
and DataTableColumnOrder
models now conforms to Equatablerows
property is now available allowing you to access the current datasource as it is - maintained by SwiftDataTable.public func data(for indexPath: IndexPath) -> DataTableValueType
This method can be used as a convenience method or you can use the rows
property to access the multi-dimensional array manually.
Cocoapod dependencies removed from the demo project.
Going forwards the library will support Swift 4.2 support. There's also a new did select and deselect delegate method:
/// Fired when a cell is selected.
///
/// - Parameters:
/// - dataTable: SwiftDataTable
/// - indexPath: the index path of the row selected
@objc optional func didSelectItem(_ dataTable: SwiftDataTable, indexPath: IndexPath)
/// Fired when a cell has been deselected
///
/// - Parameters:
/// - dataTable: SwiftDataTable
/// - indexPath: the index path of the row deselected
@objc optional func didDeselectItem(_ dataTable: SwiftDataTable, indexPath: IndexPath)
Now all these delegate methods are available for customising your swift data table. All these methods are optionals and default values will be provided. This is not a breaking change.
These same properties are also available in the DataTableConfiguration class allowing you to provide more defaults without requiring a delegate. The delegate is useful if you want to customise dynamically. I.e. specifying different row heights for different row indexes.
/// An optional delegate for further customisation. Default values will be used retrieved from the SwiftDataTableConfiguration file. This will can be overridden and passed into the SwiftDataTable constructor incase you wish not to use the delegate.
@objc public protocol SwiftDataTableDelegate: class {
/// Specify custom heights for specific rows. A row height of 0 is valid and will be used.
///
/// - Parameters:
/// - dataTable: SwiftDataTable
/// - index: the index of the row to specify a custom height for.
/// - Returns: the desired height for the given row index
@objc optional func dataTable(_ dataTable: SwiftDataTable, heightForRowAt index: Int) -> CGFloat
/// Specify custom widths for columns. This method once implemented overrides the automatic width calculation for remaining columns and therefor widths for all columns must be given. This behaviour may change so that custom widths on a single column basis can be given with the automatic width calculation behaviour applied for the remaining columns.
/// - Parameters:
/// - dataTable: SwiftDataTable
/// - index: the index of the column to specify the width for
/// - Returns: the desired width for the given column index
@objc optional func dataTable(_ dataTable: SwiftDataTable, widthForColumnAt index: Int) -> CGFloat
/// Column Width scaling. If set to true and the column's total width is smaller than the content size then the width of each column will be scaled proprtionately to fill the frame of the table. Otherwise an automatic calculated width size will be used by processing the data within each column.
/// Defaults to true.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: whether you wish to scale to fill the frame of the table
@objc optional func shouldContentWidthScaleToFillFrame(in dataTable: SwiftDataTable) -> Bool
/// Section Header floating. If set to true headers can float and remain in view during scroll. Otherwise if set to false the header will be fixed at the top and scroll off view along with the content.
/// Defaults to true
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: whether you wish to float section header views.
@objc optional func shouldSectionHeadersFloat(in dataTable: SwiftDataTable) -> Bool
/// Section Footer floating. If set to true footers can float and remain in view during scroll. Otherwise if set to false the footer will be fixed at the top and scroll off view along with the content.
/// Defaults to true.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: whether you wish to float section footer views.
@objc optional func shouldSectionFootersFloat(in dataTable: SwiftDataTable) -> Bool
/// Search View floating. If set to true the search view can float and remain in view during scroll. Otherwise if set to false the search view will be fixed at the top and scroll off view along with the content.
// Defaults to true.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: whether you wish to float section footer views.
@objc optional func shouldSearchHeaderFloat(in dataTable: SwiftDataTable) -> Bool
/// Disable search view. Hide search view. Defaults to true.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: whether or not the search should be hidden
@objc optional func shouldShowSearchSection(in dataTable: SwiftDataTable) -> Bool
/// The height of the section footer. Defaults to 44.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: the height of the section footer
@objc optional func heightForSectionFooter(in dataTable: SwiftDataTable) -> CGFloat
/// The height of the section header. Defaults to 44.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: the height of the section header
@objc optional func heightForSectionHeader(in dataTable: SwiftDataTable) -> CGFloat
/// The height of the search view. Defaults to 44.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: the height of the search view
@objc optional func heightForSearchView(in dataTable: SwiftDataTable) -> CGFloat
/// Height of the inter row spacing. Defaults to 1.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: the height of the inter row spacing
@objc optional func heightOfInterRowSpacing(in dataTable: SwiftDataTable) -> CGFloat
/// Control the display of the vertical scroll bar. Defaults to true.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: whether or not the vertical scroll bars should be shown.
@objc optional func shouldShowVerticalScrollBars(in dataTable: SwiftDataTable) -> Bool
/// Control the display of the horizontal scroll bar. Defaults to true.
///
/// - Parameter dataTable: SwiftDataTable
/// - Returns: whether or not the horizontal scroll bars should be shown.
@objc optional func shouldShowHorizontalScrollBars(in dataTable: SwiftDataTable) -> Bool
}
DataTableConfiguration
object using a GenericDataTableViewController
.DataTableConfiguration
object has a new property called shouldShowFooter
with a default value of true
. This property allows the user to override whether footers should be shown or not.layoutAttributesForRect
method to use a binary search instead of filtering through all cached layouattributes. This sees a speed factory of 300 during scroll.SwiftDataTableLayout
class by preventing unnecessary delegate calls for column widths.Implements Data Source with bug fix.