# Data Table > A table filled from a list, with a filter, sortable columns, row selection and pages. Source: https://native.shellui.dev/docs/components/data-display/data-table ## Installation ```bash shellui-native add data-table ``` **Platforms:** MAUI · Avalonia. Also installs `icon`, `button`, `table`, `input`, `checkbox`. ## Usage ### Basic **MAUI** ```xml ``` **Avalonia** ```xml ``` [Live preview](https://native.shellui.dev/preview/index.html?c=data-table-basic) `ItemsSource` takes any list, and an `ObservableCollection` refreshes the table as it changes. Each column names the item property it shows: ```csharp public record Invoice(string Number, string Customer, string Status, DateTime Date, decimal Amount); ``` - **Filter.** Every word typed in the field must be in the text of some column. - **Sort.** A sortable header cycles ascending, descending and unsorted. Numbers and dates sort by value. - **Selection.** `ShowSelection` adds a checkbox column. The header checkbox selects every row that passes the filter, across pages. `SelectedItems` holds the items, and `SelectionChanged` passes them. - **Pages.** Ten rows at a time, with Previous and Next. Change the count with `PageSize`, or turn pages off with `ShowPagination="False"`. Cells show text only. For badges or buttons in cells, build the rows yourself with [Table](https://native.shellui.dev/docs/components/data-display/table.md). ### Columns `Width` takes a Grid column width: `*`, `2*` or a fixed number. `Format` is a .NET format string such as `C` or `MMM d, yyyy`. After changing an item's values in place, call `Refresh()`. ### Trimming and NativeAOT `Property` is read by name at run time. In an app published with trimming or NativeAOT, set `Value` in code instead, so the property isn't trimmed away: ```csharp InvoiceTable.Columns[0].Value = item => ((Invoice)item).Number; ``` ## MAUI and Avalonia - On Avalonia, sortable headers are tab stops, pressed with Enter or Space, and keep focus after sorting. - On Avalonia a click on a row's checkbox doesn't raise `RowTapped`. ## API ### DataTable XAML children go to `Columns`. | Property | Type | Default | Description | |---|---|---|---| | `ItemsSource` | `IEnumerable` (MAUI) · `IEnumerable?` (Avalonia) | `null` | The items to show, one row each. An `ObservableCollection` refreshes the table as it changes. | | `ShowFilter` | `bool` | `true` | Shows the filter field above the table. | | `FilterPlaceholder` | `string` | `"Filter..."` | Hint in the empty filter field. | | `ShowPagination` | `bool` | `true` | Splits the rows into pages, with Previous and Next. | | `PageSize` | `int` | `10` | Rows per page while `ShowPagination` is on. | | `ShowSelection` | `bool` | `false` | Adds a checkbox column; the header checkbox selects every row that passes the filter. | | `EmptyText` | `string` | `"No results."` | Shown when no row passes the filter. | | `MinimumContentWidth` | `double` | `0` | Below this width the table scrolls sideways instead of squeezing its columns. 0 never scrolls. | | Event | Arguments | Description | |---|---|---| | `SelectionChanged` | `IReadOnlyList` | The selection changed; passes the selected items. | | `RowTapped` | `object` | A row was tapped; passes its item. | | Method | Description | |---|---| | `Refresh()` | Re-reads the items and columns. Call it after changing an item's values or a column. | | `GoToPage(int page)` | Shows a page, counting from 1. | | `SortBy(DataTableColumn? column, bool descending = false)` | Sorts by a column; call it again to reverse, and with null to restore the source order. | | `ClearSelection()` | Unselects every row. | ### DataTableColumn | Property | Type | Default | Description | |---|---|---|---| | `Header` | `string` | — | Text in the column's header cell. | | `Property` | `string` | — | The name of the item property this column shows. | | `Value` | `Func?` | `null` | Reads the column's value from an item; replaces `Property`. Set it in code. | | `Format` | `string` | — | A .NET format string for the value, such as `C` or `MMM d, yyyy`. | | `Width` | `string` | `"*"` | A Grid column width: `*`, `2*` or a fixed number. | | `IsSortable` | `bool` | `true` | Whether tapping the header sorts by this column. | | `IsBold` | `bool` | `false` | Medium-weight text, for the row's key column. | | `HorizontalTextAlignment` | `TextAlignment` | `Start` | Text alignment in the cell. |