Default Cell Configuration

Customise the appearance of default cells without creating custom cell classes.

How It Works

The defaultCellConfiguration callback provides a simple way to customise fonts, colours, and other properties of the default DataCell without the boilerplate of a full custom cell provider.

Your callback only overrides what you explicitly set. Everything else keeps its default styling.

Basic Usage

var config = DataTableConfiguration()
config.defaultCellConfiguration = { cell, value, indexPath, isHighlighted in
    cell.dataLabel.font = UIFont(name: "Avenir-Medium", size: 14)
    cell.dataLabel.textColor = .label
}

let table = SwiftDataTable(data: items, columns: columns, options: config)

Parameters

ParameterTypeDescription
cellDataCellThe cell instance to configure
valueDataTableValueTypeThe data value being displayed
indexPathIndexPathPosition where section = column, item = row
isHighlightedBooltrue if the cell is in a sorted column

Common Patterns

Highlight Negative Values

config.defaultCellConfiguration = { cell, value, _, _ in
    if let number = value.doubleValue, number < 0 {
        cell.dataLabel.textColor = .systemRed
    } else {
        cell.dataLabel.textColor = .label
    }
}

Per-Column Styling

config.defaultCellConfiguration = { cell, _, indexPath, _ in
    switch indexPath.section {
    case 0:  // First column (e.g., ID)
        cell.dataLabel.font = .monospacedDigitSystemFont(ofSize: 12, weight: .regular)
    case 3:  // Fourth column (e.g., Status)
        cell.dataLabel.textAlignment = .center
    default:
        break
    }
}

Highlight Sorted Columns

config.defaultCellConfiguration = { cell, _, indexPath, isHighlighted in
    if isHighlighted {
        cell.backgroundColor = .systemYellow.withAlphaComponent(0.2)
    } else {
        cell.backgroundColor = indexPath.item % 2 == 0 ? .systemGray6 : .systemBackground
    }
}

When to Use Custom Cells Instead

If you need more advanced customisation, such as custom subviews (images, buttons, badges), complex multi-element layouts, or different cell types per column, then you should create custom cells using DataTableCustomCellProvider.