TableModel

public class TableModel : ObservableObject

TableModel is the data structure being used in DataTable View.

Code Usage:

let header = TableRowItem(leadingAccessories: [], trailingAccessory: nil, data: titles)
let model = TableModel(headerData: header, rowData: res, isFirstRowSticky: true, isFirstColumnSticky: true, showListView: true)
model.columnAttributes = ...
model.didSelectRowAt = { rowIndex in
   print("Tapped row \(rowIndex)")
}

/// 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)")
}
  • Edit mode for DataTable

    See more

    Declaration

    Swift

    public enum EditMode : Int, CaseIterable
  • TableRowItem, header data for displaying.

    Declaration

    Swift

    @Published
    public var headerData: TableRowItem? { get set }
  • Data for each row. Header is not included.

    Declaration

    Swift

    public var rowData: [TableRowItem] { get set }
  • Set header to be sticky.

    Declaration

    Swift

    @Published
    public var isHeaderSticky: Bool { get set }
  • Set first column to be sticky.

    Declaration

    Swift

    @Published
    public var isFirstColumnSticky: Bool { get set }
  • Set horizontal scrolling.

    Declaration

    Swift

    @Published
    public var horizontalScrolling: Bool { get set }
  • Show list view in iPhone portrait mode.

    Declaration

    Swift

    @Published
    public var showListView: Bool { get set }
  • Column attribute for each column.

    Declaration

    Swift

    @Published
    public var columnAttributes: [ColumnAttribute] { get set }
  • Undocumented

    Declaration

    Swift

    public func columnAttribute(for columnIndex: Int) -> ColumnAttribute
  • row alignment

    Declaration

    Swift

    @Published
    public var rowAlignment: RowAlignment { get set }
  • Switching between normal and editing mode.

    Declaration

    Swift

    @available(*, deprecated, renamed: "editMode")
    @Published
    public var isEditing: Bool { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var editMode: EditMode { get set }
  • Enable or disable pinch and zoom.

    Declaration

    Swift

    @Published
    public var isPinchZoomEnable: Bool { get set }
  • Selection did change handler.

    Declaration

    Swift

    public var didSelectRowAt: ((_ index: Int) -> Void)?
  • value did change

    Declaration

    Swift

    public var valueDidChange: ((DataTableChange) -> Void)?
  • cell tapped closure to store (rowIndex, columnIndex); rowIndex starts from header if it exists

    Declaration

    Swift

    public var cellTapped: ((Int, Int) -> Void)?
  • a closure to call after the keyboard shown or hidden; typically used to adjust the focused text field position when the keyboard is shown

    Declaration

    Swift

    public var keyboardDidShowOrHide: ((CGRect) -> Void)?
  • Selected Indexes.

    Declaration

    Swift

    @Published
    public var selectedIndexes: [Int] { get set }
  • show row dividers in every number of Rows; The values must be >= 1; The default is 1.

    Declaration

    Swift

    @Published
    public var everyNumOfRowsToShowDivider: Int { get set }
  • show or hide row dividers

    Declaration

    Swift

    @Published
    public var showRowDivider: Bool { get set }
  • show or hide first column divider

    Declaration

    Swift

    @Published
    public var showColoumnDivider: Bool { get set }
  • the row divider height

    Declaration

    Swift

    @Published
    public var rowDividerHeight: CGFloat { get set }
  • the row divider color

    Declaration

    Swift

    @Published
    public var rowDividerColor: Color { get set }
  • the column divider width

    Declaration

    Swift

    @Published
    public var columnDividerWidth: CGFloat { get set }
  • the column divider color

    Declaration

    Swift

    @Published
    public var columnDividerColor: Color { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var headerCellPadding: EdgeInsets? { get set }
  • Undocumented

    Declaration

    Swift

    @Published
    public var dataCellPadding: EdgeInsets? { get set }
  • min row height

    Declaration

    Swift

    @Published
    public var minRowHeight: CGFloat { get set }
  • min column width

    Declaration

    Swift

    @Published
    public var minColumnWidth: CGFloat { get set }
  • whether allows to display partial row; For Table Card, set this to false

    Declaration

    Swift

    @Published
    public var allowsPartialRowDisplay: Bool { get set }
  • background color

    Declaration

    Swift

    @Published
    public var backgroundColor: Color { get 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

    Declaration

    Swift

    public var validateDataItem: ((_ rowIndex: Int, _ columnIndex: Int, _ dataItem: DataItem) -> (Bool, String?))?
  • a closure to provide a DataListItem type dataItem located at (rowIndex, columnIndex) for an array of Strings and a title for inline editing mode

    Declaration

    Swift

    public var listItemDataAndTitle: ((_ rowIndex: Int, _ columnIndex: Int) -> (listItems: [String], title: String))?
  • a closure to provide contentOffset and the index of visible rows and columns when the user scrolls the content view within the DataTable.

    Declaration

    Swift

    public var didScroll: ((_ contentOffset: CGPoint, _ indexOfRows: [Int], _ indexOfColumns: [Int]) -> Void)?
  • Public initializer for TableModel.

    Declaration

    Swift

    public init(headerData: TableRowItem? = nil,
                rowData: [TableRowItem] = [],
                isHeaderSticky: Bool = false,
                isFirstColumnSticky: Bool = false,
                columnAttributes: [ColumnAttribute] = [],
                rowAlignment: RowAlignment = .top,
                isPinchZoomEnable: Bool = false,
                showRowDivider: Bool = true,
                rowDividerHeight: CGFloat = 1,
                rowDividerColor: Color = Color.preferredColor(.separator),
                everyNumOfRowsToShowDivider: Int = 1,
                showColoumnDivider: Bool = true,
                columnDividerWidth: CGFloat = 1,
                columnDividerColor: Color = Color.preferredColor(.separator),
                headerCellPadding: EdgeInsets? = nil,
                dataCellPadding: EdgeInsets? = nil,
                minRowHeight: CGFloat = 48,
                minColumnWidth: CGFloat = 48,
                allowsPartialRowDisplay: Bool = true,
                backgroundColor: Color = Color.preferredColor(.secondaryGroupedBackground),
                showListView: Bool = false,
                editMode: EditMode = .none)

    Parameters

    headerData

    Header data for displaying

    rowData

    Data for each row

    isHeaderSticky

    Set header to be sticky

    isFirstColumnSticky

    Set first column to be sticky

    columnAttributes

    Column attribute for each column

    rowAlignment

    Row alighnemt

    isPinchZoomEnable

    Set if pinch and zoom enable, the default is false.

    showRowDivider

    Show or hide row dividers

    rowDividerHeight

    The row divider height

    rowDividerColor

    The row divider color

    everyNumOfRowsToShowDivider

    Show row dividers in every number of Rows; The values must be >= 1; The default is 1.

    showColoumnDivider

    Show or hide first column divider

    columnDividerWidth

    The column divider width

    columnDividerColor

    The column divider color

    headerCellPadding

    Custom header cell’s padding

    dataCellPadding

    Custom data cell’s padding

    minRowHeight

    Min row height

    minColumnWidth

    Min column width

    allowsPartialRowDisplay

    Whether allows to display partial row; For Table Card, set this to false

    backgroundColor

    Background color

    showListView

    Show list view in iPhone portrait mode

    editMode

    one of edit mode; The default is .none.

  • Undocumented

    Declaration

    Swift

    public func copy() -> TableModel
  • check if the model contains no data

    Declaration

    Swift

    public var isNoData: Bool { get }
  • Save the model after the editing. If changes were not valid then those changes are rolled back to original values.

    Declaration

    Swift

    public func onSave(_ isSave: Bool) -> [DataTableChange]

    Parameters

    isSave

    Save it or not

    Return Value

    Return an array of changes