DataTable
@MainActor
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 @MainActor public var model: TableModel { get set } -
Public initializer for DataTable
Declaration
Swift
@MainActor public init(model: TableModel)Parameters
modelTableModel Object.
-
Body of the View
Declaration
Swift
@MainActor public var body: some View { get } -
Set the background color.
Declaration
Swift
@MainActor func backgroundColor(_ color: Color) -> DataTable -
Set header to be sticky or not.
Declaration
Swift
@MainActor func headerSticky(_ value: Bool) -> DataTable -
Set first column to be sticky or not.
Declaration
Swift
@MainActor func firstColumnSticky(_ value: Bool) -> DataTable -
Set pinch and zoom enable or not.
Declaration
Swift
@MainActor func pinchZoomEnable(_ value: Bool) -> DataTable -
Show list view or not
Declaration
Swift
@MainActor func showListView(_ value: Bool) -> DataTable -
Toggles the DataTable into and out of editing mode.
Declaration
Swift
@available(*, deprecated) @MainActor func editingMode(_ value: Bool = false) -> DataTableParameters
valuetrue to enter editing mode, false to leave it. The default value is false .
Return Value
DataTable
-
Show or hide column divider.
Declaration
Swift
@MainActor func showColumnDivider(_ value: Bool = true) -> DataTableParameters
valuetrue to show; false to hide
Return Value
DataTable
-
Show or hide row divider.
Declaration
Swift
@MainActor func showRowDivider(_ value: Bool = true) -> DataTableParameters
valuetrue to show; false to hide
Return Value
DataTable
-
Pads all cells of this DataTable using the edges and padding amount you specify.
Declaration
Swift
@MainActor func dataCellPadding(_ insets: EdgeInsets) -> DataTableParameters
insetsThe 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
@MainActor func headerCellPadding(_ insets: EdgeInsets) -> DataTableParameters
insetsThe 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
@MainActor func minRowHeight(_ value: CGFloat) -> DataTable -
Set minimum column width
Declaration
Swift
@MainActor func minColumnWidth(_ value: CGFloat) -> DataTable -
Set whether to allow partial row display
Declaration
Swift
@MainActor func allowsPartialRowDisplay(_ value: Bool) -> DataTable -
Set row alignment mode
Declaration
Swift
@MainActor 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
@MainActor func sizeThatFits(_ size: CGSize) -> CGSize -
Returns the rect for the specified cell with rowIndex and columnIndex
Declaration
Swift
@MainActor func rectForCell(at rowIndex: Int, columnIndex: Int, isRelativeToContentOffset: Bool = false) -> CGRectParameters
rowIndexthe row index; rowIndex starts from header if it exists
columnIndexthe column index
isRelativeToContentOffsetsubtract ScrollView’s contentOffset if it is true
Return Value
Return the rect