GitHub

Search Integration

Add search functionality using the built-in search bar or native iOS navigation search.

SwiftDataTables includes built-in search that filters rows as users type. No setup required — it works out of the box. You can choose between an embedded search bar (visible in the table header) or native iOS navigation bar search.

How Search Works

When a user types in the search bar:

  1. Each row is checked against the search text
  2. A row matches if any column contains the search text (case-insensitive substring match)
  3. Non-matching rows are hidden with animation
  4. Clearing the search restores all rows

Search filters the displayed values (what users see in cells), not the underlying model data. If a column shows "$49.99" but the model stores 49.99, users search for "$49", not "49".

Choosing a Search Style

StyleAppearanceBest For
EmbeddedSearch bar inside the table headerStandalone tables, modals, when nav bar is unavailable
Navigation BarNative iOS search in the navigation barFull-screen lists, when you want standard iOS UX

The embedded search bar is enabled by default and appears at the top of the table. It floats (stays visible while scrolling) by default.

var config = DataTableConfiguration()

// These are the defaults:
config.shouldShowSearchSection = true   // Show the search bar
config.shouldSearchHeaderFloat = true   // Keep it visible while scrolling

let dataTable = SwiftDataTable(columns: columns, options: config)

If you're handling search externally (your own search UI, or no search needed), hide it:

var config = DataTableConfiguration()
config.shouldShowSearchSection = false

For a native iOS experience, move search to the navigation bar. This is the standard pattern for list screens in iOS apps.

Quick Setup

One line to install a search controller on your view controller:

override func viewDidLoad() {
    super.viewDidLoad()
    
    dataTable = SwiftDataTable(columns: columns)
    view.addSubview(dataTable)
    
    // This sets up UISearchController and wires it to the table
    dataTable.installSearchController(on: self)
}

When using navigation bar search, you'll typically want to hide the embedded search bar: config.shouldShowSearchSection = false

Customizing the Search Controller

For more control, create the search controller yourself and customize it:

// Get a pre-wired search controller from the table
let searchController = dataTable.makeSearchController()

// Customize it
searchController.searchBar.placeholder = "Search employees..."
searchController.obscuresBackgroundDuringPresentation = false

// Install it yourself
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false  // Always visible

You can trigger search from code, useful for deep links or saved filters:

// Apply a search term programmatically
dataTable.search("engineering")

// Clear the search
dataTable.search("")