FUIDataTable
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
public var model: FUIDataTableModel!
-
Boolean for switching the data table in normal and editing mode.
Declaration
Swift
@available(*, deprecated, renamed: "editMode") public var isEditing: Bool { get set }
-
edit mode
Declaration
Swift
public var editMode: FUIDataTableModel.EditMode { get set }
-
Setting background color for data table.
Declaration
Swift
public var dataTableBackgroundColor: UIColor? { get set }
-
Set header to be sticky or not.
Declaration
Swift
public var isHeaderSticky: Bool { get set }
-
Set first column to be sticky or not.
Declaration
Swift
public var isFirstColumnSticky: Bool { get set }
-
Set pinch and zoom enble or not.
Declaration
Swift
public var isPinchZoomEnable: Bool { get set }
-
Show list view or not
Declaration
Swift
public func showListView(_ value: Bool)
-
Show or hide column divider.
Declaration
Swift
public func showColumnDivider(_ value: Bool)
Parameters
value
true to show; false to hide
-
Show or hide row divider.
Declaration
Swift
public func showRowDivider(_ value: Bool)
Parameters
value
true to show; false to hide
-
Pads all header cells of this DataTable using the edges and padding amount you specify.
Declaration
Swift
public func headerCellPadding(_ value: UIEdgeInsets?)
Parameters
insets
The edges and amounts to inset.
-
Pads all cells of this DataTable using the edges and padding amount you specify.
Declaration
Swift
public func dataCellPadding(_ value: UIEdgeInsets?)
Parameters
insets
The edges and amounts to inset.
-
Set minimum row height
Declaration
Swift
public func minRowHeight(_ value: CGFloat)
-
Set minimum column width
Declaration
Swift
public func minColumnWidth(_ value: CGFloat)
-
Set whether to allow partial row display
Declaration
Swift
public func allowsPartialRowDisplay(_ value: Bool)
-
Set row alignment mode
Declaration
Swift
public func rowAlignment(_ value: FUIDataTableRowAlignment)
-
save the model after the editing
Declaration
Swift
public func onSave(_ isSave: Bool) -> [FUIDataTableChange]
Parameters
isSave
Save it or not
Return Value
Return an array of changes
-
Public initializer for
FUIDataTable
.Declaration
Swift
public init(model: FUIDataTableModel)
Parameters
model
FUIDataTableModel
object. -
Undocumented
Declaration
Swift
required public init?(coder: NSCoder)
-
The preferred maximum width for the
FUIDataTable
; Setting this property affects the intrinsicContentSize.Declaration
Swift
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
public override var intrinsicContentSize: CGSize { get }
-
Asks the
FUIDataTable
to 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
open override func sizeThatFits(_ size: CGSize) -> CGSize
-
add the UIHostingController to its parent UIViewController to make sure keyboard etc work properly
Declaration
Swift
open override func didMoveToSuperview()
-
Returns the optimal size of the
FUIDataTable
based on its constraints and the specified fitting priorities. Invoking this method can cause the change of intrinsicContentSize.Declaration
Swift
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
public 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
-
a closure to store (rowIndex, columnIndex) info when a cell tapped; rowIndex: header row is at index 0 if it exists
Declaration
Swift
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
public var keyboardDidShowOrHide: ((_ rect: CGRect) -> Void)? { get set }