FUIDataTable
@MainActor
open class FUIDataTable : UIView
A FUIDataTable is a view that displaying data in either a list view or a grid table view.
Code usage:
let model = FUIDataTableModel(headerData: nil,
rowData: rowData,
isHeaderSticky: true,
isFirstColumnSticky: true,
columnAttributes: columnAttributes,
rowAlignment: .top,
isPinchZoomEnable: false,
showRowDivider: true,
showColoumnDivider: true,
headerCellPadding: UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16),
dataCellPadding: UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16),
minRowHeight: 48,
minColumnWidth: 48,
allowsPartialRowDisplay: true,
backgroundColor: .white,
showListView: false)
model.didSelectRowAt = { _ in
print(model.selectedIndexes)
}
/// 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 `FUIDataListItem` 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)")
}
let dataTable = FUIDataTable(model: model)
Theming
Supported TEXT class paths:
fdlFUIDataTable_textItem {}: TEXT theme for all cells. It has lowest priority.
fdlFUIDataTable_textItem_row2 {}: TEXT theme for one speciif column. # is the column index. It has third priority.
fdlFUIDataTable_textItem_column1 {}: TEXT theme for one specific row. # is the row index; header is row 0 if it existis. It has second priority.
fdlFUIDataTable_textItem_row2_column1{}: TEXT theme for one specific cell. Row index and column index are required. It has highest priority.
Supported TEXT properties:
font-color: Color;
font-style: UIFontTextStyle;
text-line-clamp: Integer;
text-align: NSTextAlignment;
Supported IMAGE class paths:
fdlFUIDataTable_imageItem {}: IMAGE theme for all cells. It has lowest priority.
fdlFUIDataTable_imageItem_column# {}: IMAGE theme for one speciif column. # is the column index. It has third priority.
fdlFUIDataTable_imageItem_row# {}: IMAGE theme for one specific row. # is the row index; header is row 0 if it existis. It has second priority.
fdlFUIDataTable_imageItem_row#_column# {}: IMAGE theme for one specific cell. Row index and column index are required. It has highest priority.
Supported IMAGE properties:
tint-color: Color;
image-name: String;
-
Data table’s data model.
Declaration
Swift
@MainActor public var model: FUIDataTableModel! -
Boolean for switching the data table in normal and editing mode.
Declaration
Swift
@available(*, deprecated, renamed: "editMode") @MainActor public var isEditing: Bool { get set } -
edit mode
Declaration
Swift
@MainActor public var editMode: FUIDataTableModel.EditMode { get set } -
Setting background color for data table.
Declaration
Swift
@MainActor public var dataTableBackgroundColor: UIColor? { get set } -
Set header to be sticky or not.
Declaration
Swift
@MainActor public var isHeaderSticky: Bool { get set } -
Set first column to be sticky or not.
Declaration
Swift
@MainActor public var isFirstColumnSticky: Bool { get set } -
Set pinch and zoom enble or not.
Declaration
Swift
@MainActor public var isPinchZoomEnable: Bool { get set } -
Show list view or not
Declaration
Swift
@MainActor public func showListView(_ value: Bool) -
Show or hide column divider.
Declaration
Swift
@MainActor public func showColumnDivider(_ value: Bool)Parameters
valuetrue to show; false to hide
-
Show or hide row divider.
Declaration
Swift
@MainActor public func showRowDivider(_ value: Bool)Parameters
valuetrue to show; false to hide
-
Pads all header cells of this DataTable using the edges and padding amount you specify.
Declaration
Swift
@MainActor public func headerCellPadding(_ value: UIEdgeInsets?)Parameters
insetsThe edges and amounts to inset.
-
Pads all cells of this DataTable using the edges and padding amount you specify.
Declaration
Swift
@MainActor public func dataCellPadding(_ value: UIEdgeInsets?)Parameters
insetsThe edges and amounts to inset.
-
Set minimum row height
Declaration
Swift
@MainActor public func minRowHeight(_ value: CGFloat) -
Set minimum column width
Declaration
Swift
@MainActor public func minColumnWidth(_ value: CGFloat) -
Set whether to allow partial row display
Declaration
Swift
@MainActor public func allowsPartialRowDisplay(_ value: Bool) -
Set row alignment mode
Declaration
Swift
@MainActor public func rowAlignment(_ value: FUIDataTableRowAlignment) -
save the model after the editing
Declaration
Swift
@MainActor public func onSave(_ isSave: Bool) -> [FUIDataTableChange]Parameters
isSaveSave it or not
Return Value
Return an array of changes
-
Public initializer for
FUIDataTable.Declaration
Swift
@MainActor public init(model: FUIDataTableModel)Parameters
modelFUIDataTableModelobject. -
Undocumented
Declaration
Swift
@MainActor required public init?(coder: NSCoder) -
The preferred maximum width for the
FUIDataTable; Setting this property affects the intrinsicContentSize.Declaration
Swift
@MainActor public var preferredMaxLayoutWidth: CGFloat? { get set } -
The ideal size for the
FUIDataTable, considering only properties of the view itself. Changing preferredMaxLayoutWidth can cause the change of intrinsicContentSize.Declaration
Swift
@MainActor public override var intrinsicContentSize: CGSize { get } -
Asks the
FUIDataTableto calculate and return the size that best fits all rows & columns by giving a size.width (the passed size.height is ignored). Invoking this method won’t change the intrinsicContentSize. 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 open override func sizeThatFits(_ size: CGSize) -> CGSize -
add the UIHostingController to its parent UIViewController to make sure keyboard etc work properly
Declaration
Swift
@MainActor open override func didMoveToSuperview() -
Returns the optimal size of the
FUIDataTablebased on its constraints and the specified fitting priorities. Invoking this method can cause the change of intrinsicContentSize.Declaration
Swift
@MainActor open override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize -
Returns the rect for the specified cell with rowIndex and columnIndex
Declaration
Swift
@MainActor public 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
-
a closure to store (rowIndex, columnIndex) info when a cell tapped; rowIndex: header row is at index 0 if it exists
Declaration
Swift
@MainActor public var cellTapped: ((Int, Int) -> Void)? { get set } -
a closure to call after the keybaord shown or hidden; typically used to ajust the focused text field position when the keyboard is shown
Declaration
Swift
@MainActor public var keyboardDidShowOrHide: ((_ rect: CGRect) -> Void)? { get set }