DataTable

public struct DataTable : View

A Data Table is a View that is used for displaying data in either list view or grid table view. It supports cell types of DataImageItem, DataTextItem, DataDateItem, DataTimeItem, DataDurationItem and DataListItem.

Code usage:

let model = TableModel(headerData: header, rowData: res, isFirstRowSticky: true, isFirstColumnSticky: true, showListView: false)
model.columnAttributes = ...
model.didSelectRowAt = { rowIndex in
   print("Tapped row \(rowIndex)")
}
model.selectedIndexes = [2, 3]

/// set a closure to check whether a dataItem located at (rowIndex, columnIndex) is valid; If it is valid, returns (true, nil); if it is not valid, returns false and an error message which is shown to users.
model.validateDataItem = { rowIndex, columnIndex, dataItem in
...
}

/// set a closure to provide a `DataListItem` type dataItem located at (rowIndex, columnIndex) for an array of Strings and a title for inline editing mode
model.listItemDataAndTitle = { rowIndex, columnIndex in
...
}

/// set a closure to observe a value change for inline editing mode
model.valueDidChange = { change in
    print("valueDidChange: \(change.description)")
}

DataTable(model: model)
  • Data table’s data model

    Declaration

    Swift

    @ObservedObject
    public var model: TableModel { get set }
  • Public initializer for DataTable

    Declaration

    Swift

    public init(model: TableModel)

    Parameters

    model

    TableModel Object.

  • Body of the View

    Declaration

    Swift

    public var body: some View { get }
  • Set the background color.

    Declaration

    Swift

    func backgroundColor(_ color: Color) -> DataTable
  • Set header to be sticky or not.

    Declaration

    Swift

    func headerSticky(_ value: Bool) -> DataTable
  • Set first column to be sticky or not.

    Declaration

    Swift

    func firstColumnSticky(_ value: Bool) -> DataTable
  • Set pinch and zoom enable or not.

    Declaration

    Swift

    func pinchZoomEnable(_ value: Bool) -> DataTable
  • Show list view or not

    Declaration

    Swift

    func showListView(_ value: Bool) -> DataTable
  • Toggles the DataTable into and out of editing mode.

    Declaration

    Swift

    @available(*, deprecated)
    func editingMode(_ value: Bool = false) -> DataTable

    Parameters

    value

    true to enter editing mode, false to leave it. The default value is false .

    Return Value

    DataTable

  • Show or hide column divider.

    Declaration

    Swift

    func showColumnDivider(_ value: Bool = true) -> DataTable

    Parameters

    value

    true to show; false to hide

    Return Value

    DataTable

  • Show or hide row divider.

    Declaration

    Swift

    func showRowDivider(_ value: Bool = true) -> DataTable

    Parameters

    value

    true to show; false to hide

    Return Value

    DataTable

  • Pads all cells of this DataTable using the edges and padding amount you specify.

    Declaration

    Swift

    func dataCellPadding(_ insets: EdgeInsets) -> DataTable

    Parameters

    insets

    The edges and amounts to inset.

    Return Value

    A DataTable that pads this DataTable using the specified edge insets with specified amount of padding.

  • Pads all header cells of this DataTable using the edges and padding amount you specify.

    Declaration

    Swift

    func headerCellPadding(_ insets: EdgeInsets) -> DataTable

    Parameters

    insets

    The edges and amounts to inset.

    Return Value

    A DataTable that pads this DataTable using the specified edge insets with specified amount of padding.

  • Set minimum row height

    Declaration

    Swift

    func minRowHeight(_ value: CGFloat) -> DataTable
  • Set minimum column width

    Declaration

    Swift

    func minColumnWidth(_ value: CGFloat) -> DataTable
  • Set whether to allow partial row display

    Declaration

    Swift

    func allowsPartialRowDisplay(_ value: Bool) -> DataTable
  • Set row alignment mode

    Declaration

    Swift

    func rowAlignment(_ value: RowAlignment) -> DataTable
  • Asks the DataTable to calculate and return the size that best fits all rows & columns by giving a size.width (the passed size.height is ignored). Warning: it is a sync process so it may take long time if the DataTable has a lot of rows and columns.

    Declaration

    Swift

    func sizeThatFits(_ size: CGSize) -> CGSize
  • Returns the rect for the specified cell with rowIndex and columnIndex

    Declaration

    Swift

    func rectForCell(at rowIndex: Int, columnIndex: Int, isRelativeToContentOffset: Bool = false) -> CGRect

    Parameters

    rowIndex

    the row index; rowIndex starts from header if it exists

    columnIndex

    the column index

    isRelativeToContentOffset

    subtract ScrollView’s contentOffset if it is true

    Return Value

    Return the rect