Version 1.0.0. A short overview is in the README.md file and the release history is in the CHANGELOG.md file, both in the root folder of the package.
Overview
Data Table is a table for Unity UI (uGUI). You give a DataTableView a list of rows and a few column definitions, and you get a scrolling table with a fixed header that can be sorted, filtered, selected from, resized and scrolled with the mouse, the keyboard, a gamepad or a finger.
- Virtualised rows. Only the rows the window can show have GameObjects. They are reused as you scroll, so a hundred thousand rows cost the same number of objects as thirty.
- Typed columns. A column is a
TableColumn<TRow>built from delegates (p => p.Name). The package does not use reflection on your row type, so there is nothing for IL2CPP stripping to remove. - Custom cells that keep their row. A cell is created once per row object and is bound again to the right row after every sort, filter and data change.
- Built for no allocation while scrolling. Once the row objects exist and the number texts are cached (measured on a second pass over the same range), the table allocates nothing while it only scrolls. Number columns cache their formatted text per row. The measured numbers are in Performance.
What you do not have to do: install a library, write shaders, add an importer, or set anything up per platform. The package is C# only: no native code, no shaders, no materials, and nothing is loaded from a network.
What it is not: a UI Toolkit control (Unity ships MultiColumnListView there), a spreadsheet, or a database browser. See Limitations.
Requirements
- Unity 6000.0.84f1 or newer; that is the minimum the package declares. What was run on which Unity version is listed in Platform support and tested on.
- The built-in modules UI and IMGUI. The package declares them, so Unity enables them with the package.
- The Unity UI package,
com.unity.ugui. Every new Unity project has it. Without it the package's assembly is not compiled and its types do not exist. - An EventSystem in the scene, with an input module, and a
GraphicRaycasteron the Canvas that holds the table. Creating a Canvas from the GameObject menu adds the EventSystem too. - Optional: TextMeshPro, to draw text with it. TextMeshPro is part of
com.unity.uguiin Unity 6; it needs the TMP Essential Resources (Window > TextMeshPro > Import TMP Essential Resources) or a font asset assigned in the style. - Optional: the Input System package. The table works with the Input Manager, the Input System or both. See Scrolling, keyboard, gamepad and touch for what is read where.
- No third-party dependencies, no native code, no shaders.
Installation
From the Asset Store
- Open the Package Manager: Window > Package Manager in Unity 6.0, Window > Package Management > Package Manager in Unity 6.3.
- Select My Assets and find Data Table.
- Click Install.
Unity installs Data Table as a package. It appears under Packages > Data Table in the Project window and its files are read-only. Your own scripts, styles and scenes stay under Assets/.
Demo scenes
In the Package Manager, select Data Table, open the Samples tab and import Demo. Unity copies the sample into your project under Assets/Samples, where you can change it.
| Scene | What it shows |
|---|---|
00 Menu |
Launcher with one button per scene. |
01 Stress Test |
100,000 rows, a frame-rate readout, the number of row objects, a filter field wired in the Inspector, and buttons for sorting, scrolling to a row and adding 1,000 rows. |
02 Leaderboard |
Two custom cells, RankBadgeCell and ProgressBarCell, that stay with their row after a sort. Double-click a row to activate it. |
03 Inventory |
Selection, a button that switches between Single and Multiple, a detail panel that follows SelectionChanged, and a style asset (Styles/Compact.asset) with smaller rows. |
04 CSV Viewer |
A CSV file shown with a CsvTable component and a filter field, with no script. |
Things to know:
- The sample needs the uGUI package. In a project without it the sample scripts are not compiled, and the scenes show missing scripts until the package is installed.
- The sample draws its text with Unity's built-in font and uses neither TextMeshPro nor any font file.
00 Menuloads the other scenes by name, so all five scenes must be in the Scene List (File > Build Profiles) with00 Menufirst. This is needed in the Editor as well as in a build. If a scene is missing, the menu says so on screen.- An EventSystem is created at runtime by the sample, with the input module that matches your project. A
DataTableViewdoes not create one itself. 00 Menuhas a smallluanrobs.com/data-tableline in its footer that opens the product page only when it is clicked. Delete theSite Linkobject to remove it.- A
README.txtinside the sample describes each scene and its scripts.
Quick start
Without code, from a CSV file
- Create a Canvas from the GameObject menu (Unity adds an EventSystem with it).
- Under it, create an empty UI object and give it the size you want.
- Add Component > luanrobs > Data Table View.
- Add Component > luanrobs > CSV Table.
- Drag a
.csvor.txtfile into Csv and press Play.
To add a search box, create an input field, and in its On Value Changed (String) list add the table object and choose DataTableView.FilterText (the dynamic string entry). This is how scene 04 CSV Viewer does it.
From code
using System.Collections.Generic;
using Luanrobs.DataTable;
using UnityEngine;
using UnityEngine.UI;
public sealed class Player
{
public string Name;
public int Score;
public float Progress;
}
public sealed class ProgressCell : TableCell<Player>
{
private RectTransform fill;
protected override void OnCreate()
{
Image track = CreateImage("Track", RectTransform, new Color32(0x1E, 0x2D, 0x45, 0xFF));
track.rectTransform.offsetMin = new Vector2(8f, 8f);
track.rectTransform.offsetMax = new Vector2(-8f, -8f);
Image bar = CreateImage("Fill", track.rectTransform, new Color32(0xC9, 0xA5, 0x7A, 0xFF));
fill = bar.rectTransform;
}
protected override void OnBind(Player row)
{
fill.anchorMax = new Vector2(Mathf.Clamp01(row.Progress), 1f);
}
private static Image CreateImage(string name, Transform parent, Color color)
{
GameObject go = new GameObject(name, typeof(RectTransform), typeof(Image));
go.transform.SetParent(parent, false);
Image image = go.GetComponent<Image>();
image.color = color;
image.raycastTarget = false;
RectTransform rect = image.rectTransform;
rect.anchorMin = Vector2.zero;
rect.anchorMax = Vector2.one;
rect.offsetMin = Vector2.zero;
rect.offsetMax = Vector2.zero;
return image;
}
}
public class PlayersTable : MonoBehaviour
{
[SerializeField] private DataTableView table;
private TableData<Player> data;
private void Start()
{
List<Player> players = new List<Player>
{
new Player { Name = "Amber Falcon", Score = 4200, Progress = 0.80f },
new Player { Name = "Copper Anvil", Score = 3100, Progress = 0.35f },
new Player { Name = "Violet Lantern", Score = 5800, Progress = 0.95f },
};
data = table.SetData(players, new[]
{
new TableColumn<Player>("Name", p => p.Name) { Width = 220f, Flex = 1f },
new TableColumn<Player>("Score", p => p.Score, "N0") { Width = 100f },
new TableColumn<Player>("Progress", () => new ProgressCell())
{
Width = 160f,
Compare = (a, b) => a.Progress.CompareTo(b.Progress),
},
});
table.RowClicked += rowIndex => Debug.Log(data[rowIndex].Name);
}
}
Assign the DataTableView of a table object to Table in the Inspector and press Play. Click a header to sort, drag the edge of a header to resize a column, click a row to select it.
SetData copies the rows into the table's own list and returns a TableData<Player>, the handle you keep to change rows later. The table builds its GameObjects in Play mode only; data set in Edit mode appears when Play mode starts.
Rows and columns
DataTableView.SetData<TRow>(IEnumerable<TRow> rows, IReadOnlyList<TableColumn<TRow>> columns) shows rows of any class or struct. A call replaces any previous data, of any row type: the previous TableData becomes detached (IsAttached is false, View is null) and keeps working on its own rows, but nothing is shown. After SetData the scroll position is at the top left, the selection and the sort are cleared, and column widths come from the column definitions. FilterText is kept and applied to the new rows. ClearData() removes rows and columns.
Rows are addressed by row index: the position in the row list, 0-based, whatever the sort and the filter. A display index is the position on screen after filter and sort. Every public member takes and returns row indices unless its name says display; GetDisplayIndex(rowIndex) returns the position on screen (or -1 when the filter hides the row) and GetRowIndex(displayIndex) converts back.
Columns
A TableColumn<TRow> has three constructors.
| Constructor | Use | Defaults it sets |
|---|---|---|
TableColumn(string header, Func<TRow, string> text) |
A text column. | Sortable: Compare compares the texts with StringComparison.OrdinalIgnoreCase. A null text counts as empty. |
TableColumn(string header, Func<TRow, double> number, string format = "0.##") |
A number column. Integers and floats convert to double. |
Right-aligned, sorted by value (double.CompareTo, where NaN sorts before every number), CacheText on. The text is value.ToString(format, CultureInfo.InvariantCulture); a null or empty format means "0.##". |
TableColumn(string header, Func<TableCell<TRow>> cell) |
A column drawn by custom cells. | No text, so it is not searched, writes empty CSV fields and is not sortable until you set Compare. Set Text as well to give it text for the filter and for CSV. |
Properties of every column (set them in an object initializer, before SetData):
| Property | Type | Default | Description |
|---|---|---|---|
Header |
string |
the constructor argument | Header text, and the column name in CSV. Null becomes "". |
Width |
float |
120 | Preferred width in canvas units. |
MinWidth |
float |
40 | The narrowest the column can get, by code or by dragging. Never effective below 16. |
Flex |
float |
0 | Share of the leftover width this column receives when the columns together are narrower than the table. 0 keeps the column at Width. With two flex columns of weights 1 and 2, the second receives twice as much of the leftover. A column the user resized stops flexing. |
Alignment |
TableAlignment |
Left (Right for number columns) |
Alignment of the cell text and of the header text. |
Resizable |
bool |
true | Whether the user can drag the right edge of the header to resize the column. |
Searchable |
bool |
true | Whether the text filter looks into this column. Columns without a Text delegate are never searched. |
CacheText |
bool |
false (true for number columns) | Calls the Text delegate once per row and keeps the string until the row is reported changed. Costs one reference per row. |
Text |
Func<TRow, string> |
the constructor argument | Cell text for display, the filter and CSV. |
Compare |
Comparison<TRow> |
text and number constructors: the default comparison; custom cell constructor: null | Orders two rows. Null makes the column unsortable. |
Cell |
Func<TableCell<TRow>> |
null, or the constructor argument | Creates a custom cell. Null draws Text. |
Columns never shrink below their preferred width: when they do not fit, the table scrolls horizontally. A table reads its column definitions when SetData is called and again on Rebuild(); treat a column as read-only in between.
Use CacheText (or a number column) when your Text delegate builds a string, such as a formatted date. A delegate that returns a string the row already holds needs no cache.
Changing the data
TableData<TRow> is the handle SetData returns.
| Member | What it does |
|---|---|
Rows, Columns, Count |
The current rows (a live read-only view), the columns, the number of rows. The filter does not change Count. |
this[int rowIndex] |
Gets or replaces a row. Replacing redraws the row if it is visible. |
SetRows(rows) |
Replaces every row. Sort, filter and (clamped) scroll position are kept; the selection is cleared. The rows are read completely before anything changes, so data.SetRows(data.Rows.Where(p => p.IsOnline)) works; an exception thrown by your enumerable propagates and leaves the table unchanged. |
Add, AddRange, Insert, RemoveAt, Remove, Clear |
Change the row list. Sort and filter are applied again. Insert keeps selected rows selected. RemoveAt and Remove deselect the removed row. Clear and SetRows clear the selection. AddRange, like SetRows, reads its argument completely first: a query over the table's own Rows works, and an enumerable that throws changes nothing. |
IndexOf(row) |
Row index of the first row equal to row (EqualityComparer<TRow>.Default), or -1. A linear search. |
NotifyRowChanged(rowIndex) |
Use after you changed fields of a row object. Drops the cached texts of that row and redraws it if visible. It does not move the row: sort and filter are not applied again. |
Refresh() |
Use after you changed many rows. Drops every cached text, applies filter and sort again and redraws the visible rows. |
RowFilter |
A typed Predicate<TRow> applied together with FilterText. |
GetSelectedRows(list), TryGetSelectedRow(out row) |
The selected rows in display order. |
View, IsAttached |
The view that shows the rows, or null when detached. |
The table copies the rows you give it (the references, or the values for a struct). Later changes to your own list are not seen: use the TableData members. Many changes in one frame cost one sort and filter pass, because the display order is rebuilt once, the next time it is needed.
Row changes redraw only the visible rows and never create or destroy a GameObject.
Cells and custom cells
Without a Cell factory a column draws its Text in a label. With one, the table calls the factory once per pooled row object (so about as many times as the table shows rows) and binds each cell to different rows as the table scrolls.
Derive from TableCell<TRow>:
| Member | When it runs |
|---|---|
OnCreate() |
Once, after RectTransform exists. Build the cell's UI here. |
OnBind(TRow row) |
Every time the cell has to show a row: when the row scrolls into view, after a sort or filter, when the row is reported changed. RowIndex is already set. It runs while the table scrolls, so keep it free of allocations. |
OnRowStateChanged() |
After every bind, and when IsSelected or IsHovered change. |
OnDispose() |
Once, when the table destroys the cell (on Rebuild, on new data, when the table is destroyed). The GameObjects under RectTransform are destroyed by the table; release anything else the cell created, such as textures. |
Properties: Table, RectTransform (as wide as the column, as tall as the row), Style, ColumnIndex, RowIndex (-1 before the first bind), IsSelected, IsHovered.
protected TableLabel AddLabel() adds a text label that fills the cell with the style's padding, uses the style's font and text renderer and the column's alignment, and takes the style's text colour (the selected text colour while the row is selected). Call it from OnCreate. Its Text, Color, Alignment, FontSize and FontStyle can be set; Graphic returns the underlying Text or TextMeshProUGUI.
A cell keeps no state of a previous row: draw everything from the row you are given. Anchor the UI you build to RectTransform so it follows column resizing (the example in Quick start sets the fill with an anchor). Content that sticks out is clipped by the table's viewport, not by the cell. The cell labels the table makes have Raycast Target off; do the same for graphics of your own that do not need the pointer.
If your Cell factory returns null, the table logs an InvalidOperationException that names the column and shows a text cell. See Error handling.
Sorting a custom cell column needs a Compare; text for the filter and CSV needs a Text:
new TableColumn<Player>("Rank", () => new RankBadgeCell())
{
Text = p => p.Rank.ToString(),
Compare = (a, b) => a.Rank.CompareTo(b.Rank),
Width = 80f,
}
Sorting
The table has one sort column. A header click on a sortable column that is not the sort column sorts it ascending; a click on the sort column toggles ascending and descending; a column without Compare does nothing. A click never clears the sort; ClearSort() does. Set AllowSorting to false to turn header clicks off; Sort still works.
table.Sort(2, TableSortDirection.Descending); // column index, direction
table.ClearSort(); // rows in list order again
int column = table.SortColumn; // -1 when not sorted
TableSortDirection direction = table.SortDirection;
The sort is stable: rows that compare equal keep the order of the row list, ascending and descending alike (descending reverses the comparison, not the result). Sort on a column without Compare throws InvalidOperationException; an index outside the columns throws ArgumentOutOfRangeException.
Custom compare: set Compare on the column, for example Compare = (a, b) => a.JoinedAt.CompareTo(b.JoinedAt) to sort a text column by a date instead of its text, or set Compare = null to make a column unsortable.
If your Compare throws while the order is rebuilt, the exception is logged, the sort is cleared and the rows are shown in list order.
SetData clears the sort. Row changes, a filter and SetRows keep it. SortChanged(column, direction) is raised when the sort changes, by a header click or by code; column is -1 when it was cleared.
Filtering
FilterText (a property of DataTableView) displays a row when the text of at least one searchable column contains the filter, ignoring case (ordinal comparison, no trimming). An empty string shows every row. The value is kept when the data is replaced. It can be set from an input field's On Value Changed (String) event in the Inspector.
table.FilterText = "falcon";
int shown = table.DisplayedRowCount; // rows that pass the filter
int all = table.RowCount; // rows in the list
TableData.RowFilter is a typed filter of your own, applied together with the text filter: a row is displayed when RowFilter is null or returns true for it and it matches FilterText. If it throws, the exception is logged once and the predicate is ignored until it is set again.
data.RowFilter = p => p.Score >= 1000;
The filter looks at the text of columns with Searchable true and a Text delegate. A number column's text is formatted the first time it is searched and cached afterwards; on a large list, set Searchable = false on number columns nobody searches, which makes the first filter much faster (see Performance).
Filtering and sorting run when you ask, not while the table scrolls.
Selection
SelectionMode (Inspector field Selection Mode, default Single):
| Mode | Click behaviour |
|---|---|
None |
Nothing is selected. Clicks still raise RowClicked. |
Single |
The clicked row becomes the only selected row. Modifier keys are ignored. Clicking the selected row keeps it selected. |
Multiple |
A plain click selects only that row. Ctrl (Command on macOS) + click toggles a row. Shift + click selects the displayed rows from the anchor row to the clicked row, replacing the selection (Ctrl + Shift adds to it). The anchor is the row of the last plain or Ctrl click. |
Toggle |
Every click or tap toggles the row, with no modifier keys. Made for touch screens. |
Changing the mode trims the selection: None clears it, Single keeps at most one row.
The selection is stored as row indices, so it survives sorting. A selected row that stops being displayed because of the filter is deselected. In code:
table.Select(4); // only row 4 (does not scroll)
table.SetSelected(7, true); // add row 7 (Single mode: replaces)
table.SelectAll(); // displayed rows; Multiple and Toggle only
table.ClearSelection();
bool selected = table.IsSelected(4);
int count = table.SelectedCount;
int first = table.SelectedIndex; // row index of the first selected row on screen, or -1
List<int> indices = new List<int>();
table.GetSelectedIndices(indices); // display order; the list is cleared first
List<Player> players = new List<Player>();
data.GetSelectedRows(players);
if (data.TryGetSelectedRow(out Player player)) { }
Select and SetSelected(true) on a row hidden by the filter do nothing, and in mode None they do nothing. Selected rows are drawn with selectedColor and selectedTextColor of the style.
Events
All events are raised on the main thread. Subscribers belong to the view: they are not cleared by SetData or ClearData. Each subscriber is called on its own: one that throws is logged, and the others still run.
| Event | Arguments | Raised when |
|---|---|---|
RowClicked |
int rowIndex |
The left mouse button or a touch was released on a row, and it was not the end of a drag (when DragToScroll is on). The selection is updated first. |
RowActivated |
int rowIndex |
Two clicks on the same row within 0.4 seconds of unscaled time (raised after the second RowClicked; a third click starts a new pair), or Submit (Enter, the gamepad south button) while the table has focus. Submit activates the row the keyboard cursor is on if it is selected, else the first selected row, else nothing. |
SelectionChanged |
none | The set of selected rows changed. Raised once per change, never when the set did not change (an Insert that only shifts indices raises nothing). |
SortChanged |
int column, TableSortDirection direction |
The sort changed, by a header click or by code. column is -1 when cleared. |
ColumnResized |
int column, float width |
A column's width changed because the user dragged its header edge or SetColumnWidth was called. Raised on every step of a drag. Width changes of flex columns caused by layout raise nothing. |
When SelectionChanged is raised: Select, SetSelected, SelectAll, ClearSelection, a change of SelectionMode, clicks and keys raise it before they return. Data operations (FilterText, RowFilter, Sort, and every TableData change) raise it in the next layout pass, in the same frame's LateUpdate, never synchronously. While the view is disabled or not built, the pending event is raised in the first layout pass after it is enabled.
Subscribe and unsubscribe in matching pairs:
using Luanrobs.DataTable;
using UnityEngine;
public class TableEvents : MonoBehaviour
{
[SerializeField] private DataTableView table;
private void OnEnable()
{
table.RowActivated += OnRowActivated;
table.SelectionChanged += OnSelectionChanged;
table.SortChanged += OnSortChanged;
}
private void OnDisable()
{
table.RowActivated -= OnRowActivated;
table.SelectionChanged -= OnSelectionChanged;
table.SortChanged -= OnSortChanged;
}
private void OnRowActivated(int rowIndex) => Debug.Log("Open row " + rowIndex);
private void OnSelectionChanged() => Debug.Log(table.SelectedCount + " selected");
private void OnSortChanged(int column, TableSortDirection direction) =>
Debug.Log("Sorted by column " + column + " " + direction);
}
Scrolling, keyboard, gamepad and touch
The table scrolls itself (it does not use a ScrollRect). Positions are in canvas units. It does not scroll past its content (there is no elastic overscroll).
| Input | Effect |
|---|---|
| Mouse wheel | Scrolls ScrollWheelRows rows (default 3) per step. The wheel step is limited to one unit, so the legacy and the Input System modules behave the same. |
| Shift + wheel | Scrolls sideways by the same amount. |
| Horizontal wheel, trackpad swipe sideways | Scrolls sideways by the same amount. |
Drag (left button or touch), when DragToScroll is on |
The content follows the pointer, on both axes. On release it keeps its speed and slows down. A drag does not count as a click. One pointer owns a drag until it ends: a second finger does not take over a scroll or a column resize. |
| Scrollbars | Shown only when the content is larger than the viewport on that axis and the style's scrollbarSize is above 0. A hidden scrollbar takes no room. |
| Click or tap | Gives the table focus and selects, see Selection. A click that arrives in the same frame as an earlier change of the rows (a sort, a filter, an Insert and so on) is ignored, because the row on screen still showed the data from before the change; the next click acts on the redrawn table. |
Keyboard and gamepad keys work while KeyboardNavigation is on, the table is interactable and it has focus (the EventSystem's selected object): click it, or navigate to it with a gamepad or the keyboard.
| Key | Effect |
|---|---|
| Up, Down (gamepad stick or D-pad) | Moves the selection one displayed row and scrolls it into view. At the first or last row, focus moves on to the neighbouring selectable, as for any selectable. |
| Left, Right | Scroll a table that is wider than its viewport sideways, by a quarter of the viewport width. At the left or right edge, or when nothing is hidden sideways, focus goes on to the neighbouring selectable. |
| Page Up, Page Down | Move the selection by one page of rows. |
| Home, End | Move to the first or last displayed row. |
| Shift + these keys | In Multiple mode, extend the selection as Shift + click does. |
| Ctrl+A (Command+A) | SelectAll(). |
| Ctrl+C (Command+C) | When rows are selected, copies them to the clipboard as tab-separated text, without the header line. |
| Enter, gamepad south button (Submit) | Raises RowActivated. |
In mode None the keys only scroll (one row, one page, top, bottom) and Up and Down never leave the table while it can still scroll.
What is read where: clicks, drags, the wheel, arrow keys and Submit arrive through EventSystem events, with whichever input module your project uses. Only the modifier keys, Page Up, Page Down, Home, End, select all and copy are read by the table directly: with the Input System when that package is installed and active, with the Input Manager otherwise, and not at all when neither is available. With the Input System, the Ctrl+A and Ctrl+C letters follow the keyboard layout.
From code:
table.ScrollPosition = new Vector2(0f, 640f); // canvas units, clamped
Vector2 max = table.MaxScrollPosition; // from the last layout pass
bool shown = table.ScrollToRow(50000, TableScrollAlignment.Center);
ScrollToRow scrolls vertically only and returns false, without scrolling, when the filter hides the row. Alignments: Nearest (the shortest distance, nothing when it is already visible), Top, Center, Bottom. It can be called right after SetData: the request waits for the next layout pass. Setting ScrollPosition stops any inertia. Sorting, filtering and row changes keep the scroll position (clamped); SetData resets it.
Column widths and resizing
The user resizes a column by dragging the right edge of its header (when AllowColumnResize is on and the column's Resizable is true). In code:
table.SetColumnWidth(1, 300f); // clamped between the column's MinWidth (at least 16) and 4096
float width = table.GetColumnWidth(1);
SetColumnWidth takes effect at once, makes the column stop flexing, and raises ColumnResized. GetColumnWidth returns the width from the last layout pass (flex columns included) and, before the first layout pass, the preferred width. Rebuild() returns every width to the column definitions; assigning a different Style keeps them. When the columns are wider than the table, a horizontal scrollbar appears and the header scrolls with the rows.
CSV output and CsvTable
GetCsv returns rows as CSV text (RFC 4180): fields that contain the separator, a quote or a line break are quoted, lines are separated by CR LF, and there is no line break after the last line. The field text is what each column's Text delegate returns; columns without one give empty fields. It returns "" when there are no rows.
Spreadsheets run a cell that starts with =, +, - or @ as a formula, also inside quotes, so a player name such as =HYPERLINK(...) pasted into Excel or Google Sheets would become a live formula. While Escape Csv Formulas (EscapeCsvFormulas) is on, which is the default, GetCsv, CopyCsvToClipboard and Ctrl+C write such a field with an apostrophe in front ('=HYPERLINK(...)), and spreadsheets show it as text. Fields that start with a tab or a carriage return get the apostrophe too. Plain numbers are never changed, so -3.5 and +1,250 stay as they are. Turn the option off when the text must come back exactly as your Text delegates return it and every cell is trusted.
string csv = table.GetCsv(TableCsvScope.DisplayedRows, includeHeader: true, separator: ',');
table.CopyCsvToClipboard(TableCsvScope.SelectedRows, includeHeader: false, separator: '\t');
| Scope | Rows written |
|---|---|
AllRows |
Every row, in list order. Filter and sort are ignored. |
DisplayedRows (default) |
The rows that pass the filter, in display order. |
SelectedRows |
The selected rows, in display order. |
CsvTable (Add Component > luanrobs > CSV Table, needs a DataTableView on the same object) shows a CSV file with no code.
| Field | Type | Default | Description |
|---|---|---|---|
| Csv | TextAsset |
none | The CSV text: a .csv or .txt file imported as a TextAsset. Setting it while the component is active in Play mode loads it at once; null clears the table. |
| Separator | char |
, |
The character between fields: a comma, a semicolon or a tab. It also decides how numbers that read either way are understood (see below). Takes effect at the next load. |
| First Row Is Header | bool |
true | Use the first line as column headers. When off, columns are named Column 1, Column 2... Takes effect at the next load. |
| Column Width | float |
140 | Preferred width of every column. Takes effect at the next load. |
The file is loaded in OnEnable in Play mode. Rules: the file is read as RFC 4180 (quoted fields, doubled quotes, line breaks inside quotes; a leading byte order mark is skipped); the number of columns is that of the widest record and shorter records are padded with empty cells; an empty or missing header becomes Column N; every column has a minimum width of 60 and shares leftover width equally (Flex 1). A column in which at least one cell is not empty and every non-empty cell is a number is right-aligned and sorted by value, with empty cells first; the text shown stays exactly as in the file. A number is an optional sign, digits, an optional decimal part and an optional exponent (1250, -3.5, 2e3); a thousands separator is accepted only between groups of three digits (1,250 and 12,345,678, never 1,5 or 1,2,3). With the comma separator the decimal mark is .. With any other separator a column may also use the decimal comma that spreadsheets set to many European languages write (1,5, 1.234,5): each column takes the format in which every one of its cells is a number, and a column whose cells read either way (1.500, 300) uses the decimal comma when the separator is ; and the decimal point otherwise. The culture of the device is never used, so a file sorts the same on every machine. All other columns are text columns, sorted ignoring case. A file with no records clears the table; a file with only a header line gives the columns and no rows (every column is a text column).
From code: Load(string csvText) shows CSV text that does not come from a TextAsset (a download, a file read at runtime); Reload() parses Csv again; Data is the TableData<string[]> of the rows shown now (one string array per record), or null before the first load; Table is the DataTableView. Rows added later through Data still sort numerically in numeric columns.
using Luanrobs.DataTable;
using UnityEngine;
public class LoadCsv : MonoBehaviour
{
[SerializeField] private CsvTable csvTable;
private void Start()
{
csvTable.Load("Name;Level\nAmber;12\nCopper;7");
}
}
The example above reads the text with the table's Separator, so set Separator to ; in the Inspector first (or use commas).
Styles and text
A DataTableStyle asset holds the look. Create one with Assets > Create > luanrobs > Data Table Style and assign it to Style on the table. A table with no style uses DataTableStyle.Default: cream text on navy, one shared instance created on first use and not saved. A table reads its style when it builds its rows: assigning another style through the Style property rebuilds the header and the rows with it (data, sort, filter, selection, scroll position and column widths are kept). After you change a style asset's values at runtime, call Rebuild() on the tables that use it (this also returns column widths to the definitions).
| Field | Type | Default | Description |
|---|---|---|---|
rowHeight |
float |
32 | Height of every row, in canvas units. Values below 8 are treated as 8. |
headerHeight |
float |
36 | Height of the header row. Values below 8 are treated as 8. |
cellPadding |
float |
10 | Space between a cell's left and right edges and its text. |
scrollbarSize |
float |
12 | Thickness of the scrollbars. 0 hides them; the table still scrolls. |
textRenderer |
TableTextRenderer |
LegacyText |
LegacyText or TextMeshPro. |
font |
Font |
none | Font for legacy text. Empty uses Unity's built-in font. |
tmpFont |
TMP_FontAsset |
none | Font asset for TextMeshPro text. Empty uses the TextMeshPro default font asset. Present when TextMeshPro is in the project. |
fontSize |
int |
14 | Font size of the cells. |
headerFontSize |
int |
14 | Font size of the header. |
headerFontStyle |
FontStyle |
Bold | Font style of the header. |
backgroundColor |
Color |
#0F1724 |
Colour behind the rows, visible where there are no rows. |
headerColor |
Color |
#2B3E5E |
Background of the header row. |
headerTextColor |
Color |
#F3EEDC |
Text colour of the header. |
rowColor |
Color |
#0F1724 |
Background of the rows at even display positions (the first row is position 0). |
alternateRowColor |
Color |
#1E2D45 |
Background of the rows at odd display positions. Same as rowColor for no zebra stripes. |
hoverHighlight |
bool |
true | Draw the row under the pointer with hoverColor. |
hoverColor |
Color |
#2B3E5E |
Background of the row under the pointer, when it is not selected. |
selectedColor |
Color |
#F3EEDC |
Background of selected rows. |
textColor |
Color |
#F3EEDC |
Text colour of the cells. |
selectedTextColor |
Color |
#0F1724 |
Text colour of the cells of selected rows. |
gridLineColor |
Color |
#0F1724 |
Colour of the lines between header cells and under the header. |
sortIndicatorColor |
Color |
#C9A57A |
Colour of the sort arrow in the header. |
scrollbarColor |
Color |
#1E2D45 |
Colour of the scrollbar track. |
scrollbarHandleColor |
Color |
#B9B6A8 |
Colour of the scrollbar handle. |
Row background order: selected, then hovered (with hoverHighlight), then even or odd position.
Legacy Text and TextMeshPro
Legacy Text (default) uses UnityEngine.UI.Text with Unity's built-in font and needs no setup. Each cell label is one line tall (about fontSize * 1.3, never taller than the row) and centred vertically, so text never wraps to a second line. A text that does not fit is cut at a word boundary, with no ellipsis. Keep rowHeight at least fontSize * 1.3: a label shorter than one line shows nothing.
TextMeshPro uses TextMeshProUGUI with wrapping off and an ellipsis for text that does not fit. Set textRenderer to TextMeshPro. It needs the TMP Essential Resources (Window > TextMeshPro > Import TMP Essential Resources), even when you assign your own font asset: TextMeshProUGUI reads the TMP Settings asset they contain. The font is the style's tmpFont, else the TextMeshPro default font asset. The table never opens the TMP importer window. When the TMP Settings asset is missing, or no font asset is found, the table logs one warning per Play session that says which of the two it is, and uses legacy Text.
Rich text is off in both modes: text is shown as given.
Options
Fields of DataTableView, in the Inspector and as properties:
| Field | Type | Default | Description |
|---|---|---|---|
| Style | DataTableStyle |
none | Sizes, fonts and colours. Empty uses the built-in style. |
| Selection Mode | TableSelectionMode |
Single |
None, Single, Multiple or Toggle. |
| Show Header | bool |
true | Show the header row. |
| Allow Sorting | bool |
true | Clicking a header sorts. Sort works either way. |
| Allow Column Resize | bool |
true | Dragging the right edge of a header resizes the column. SetColumnWidth works either way. |
| Drag To Scroll | bool |
true | Dragging inside the table scrolls it, with inertia. The wheel and the scrollbars work either way. Turn it off for mouse-only screens where a drag should not scroll. |
| Keyboard Navigation | bool |
true | While the table has focus: arrow keys (Left and Right scroll sideways), Page Up, Page Down, Home, End, Ctrl+A, Ctrl+C and Submit. |
| Scroll Wheel Rows | float |
3 | Rows scrolled per mouse wheel step. Values below 0 are treated as 0. |
| Escape Csv Formulas | bool |
true | CSV output and Ctrl+C put an apostrophe in front of cells a spreadsheet would run as a formula. See CSV output and CsvTable. |
Read-only properties: HasData, RowCount, DisplayedRowCount, ColumnCount, LiveRowCount (the number of row GameObjects the table has created), SortColumn, SortDirection, SelectedCount, SelectedIndex, MaxScrollPosition. Settable properties: FilterText, ScrollPosition. The table is a Selectable, so Interactable works: a table that is not interactable ignores input. Its transition is off when you add it in the Inspector; a table added with AddComponent at runtime keeps the Selectable default (Color Tint), so set table.transition = Selectable.Transition.None if a Graphic on the same GameObject should not be tinted. Keys need the table to be selectable: keep its Navigation mode other than None.
State setters and SetData work while the component is disabled, inactive or in Edit mode. Disabling and enabling the table keeps the data, sort, filter, selection, scroll position and column widths, and shows the same rows again.
Error handling
Invalid arguments throw.
An index outside its range throws
ArgumentOutOfRangeException: a row index not in0..RowCount-1(with no data, every index is out of range), a display index not in0..DisplayedRowCount-1, a column index not in0..ColumnCount-1.Insertaccepts0..Count.A null argument documented as invalid throws
ArgumentNullException:columnsofSetData, theresultslist ofGetSelectedIndicesandGetSelectedRows, the delegate of a column constructor.A null element in
columnsthrowsArgumentException.Sorton a column withoutComparethrowsInvalidOperationException.TableCell.AddLabelcalled outsideOnCreate(after the table created the cell) throwsInvalidOperationException.
Nothing else in the public API throws.
Everything else does not throw. Your code runs inside the table, so the table catches what it throws, logs it, and keeps running:
Text, aCellfactory,OnCreate,OnBind,OnRowStateChangedandOnDisposethat throw: the exception is logged withDebug.LogException, once per column until the nextSetData,RebuildorRefresh, and the cell shows nothing (a failed factory falls back to a text cell).- A
Cellfactory that returns null: anInvalidOperationExceptionnaming the column is logged (once per column) and a text cell is shown. - A
Comparethat throws while the order is rebuilt: logged, the sort is cleared (SortColumn-1) and rows are shown in list order. - A
RowFilterthat throws: logged once and ignored until it is set again. - An event subscriber that throws: logged, and the other subscribers still run.
- TextMeshPro requested without a font asset: one warning per Play session, legacy Text is used.
A detached TableData keeps working on its rows; nothing is shown. Use the table on the main thread.
Performance
The table is designed so that scrolling costs a fixed amount, whatever the number of rows.
- Live rows.
LiveRowCountdepends on the height of the table and the row height, not on the number of rows. It grows when the table grows and never shrinks (surplus row objects are deactivated). - Binding. When nothing changed, a frame binds nothing. Scrolling by k rows (fewer than are visible) binds exactly k rows. A selection change or a column layout change binds none.
- Allocation. After the row objects exist, a frame in which the table only scrolls allocates nothing in the package's code. The text comes from your
Textdelegate: a delegate that returns a stored string allocates nothing; one that builds a string allocates once per bound cell unless the column hasCacheText(then once per row until the row is reported changed). Number columns cache their formatted text per row. So: the table itself allocates nothing while scrolling, and number columns cache their text, which is formatted the first time a row is shown. - Sort and filter run when you ask, not while scrolling. They cost milliseconds on a large list.
Measured
These numbers come from the stress scene (01 Stress Test): 100,000 rows, 8 columns (4 text, 4 number), 1280 x 720, 14 row objects, default style. Machine: AMD Ryzen 5 3600, Windows 11, Direct3D 12. Unity 6000.3.12f1 Development players (a Development player is needed to read the frame's GC allocation counter), measured by the smoke driver on the final code (2026-10-21, 00:23). Your numbers will differ with your CPU, your cell contents and your build settings.
Scrolling. GC allocation per frame read with the profiler recorder "GC Allocated In Frame"; the EventSystem was disabled during the measured frames and vSync was off.
| Run | Player | Frames | Average frame time | Worst frame | Frames with any allocation |
|---|---|---|---|---|---|
| A: scroll 16 units per frame, legacy Text | Mono | 600 | 1.25 ms | 3.06 ms | 0 |
| A: scroll 16 units per frame, legacy Text | IL2CPP | 600 | 1.12 ms | 2.78 ms | 0 |
| B: jump one page per frame, legacy Text | Mono | 300 | 4.35 ms | 6.51 ms | 0 |
| B: jump one page per frame, legacy Text | IL2CPP | 300 | 3.80 ms | 6.84 ms | 0 |
| A with TextMeshPro | Mono | 600 | 1.62 ms | 4.60 ms | 0 |
| A with TextMeshPro | IL2CPP | 600 | 1.43 ms | 6.44 ms | 0 |
Each run is a second pass over the same range, after a first pass had created the row objects and cached the number texts. That first pass (reported, not judged) did allocate: in run A with legacy Text it averaged 61 bytes per frame on Mono (69 on IL2CPP), and in run B 1,495 bytes per frame on Mono (1,687 on IL2CPP), while the number texts were formatted for the first time. With TextMeshPro, the first pass of run A averaged 443 bytes per frame on Mono (451 on IL2CPP), with one frame of 30 KB.
Sort and filter, 100,000 rows, the stress scene's 4 text and 4 number columns:
| Step | Mono player | IL2CPP player | Editor (Mono, code optimization Debug) |
|---|---|---|---|
| Sort by a number column | 34 ms | 23.5 ms | 55 to 61 ms |
| Sort by a text column | 89.5 ms | 37.1 ms | 130 to 170 ms |
| Filter "falcon" over the 4 searchable text columns, while sorted (3,576 rows shown) | 35 ms | 20.5 ms | not measured the same way |
| First filter in the Editor test, over 4 searchable columns of which 2 are number columns | not measured | not measured | 380 to 488 ms |
The Editor figures come from the EditMode performance test on 100,000 generated rows, not from the stress scene; the table gives the range of four runs on the final code (two Unity versions, 2026-10-21), because the text sort and the first filter vary widely between runs on a shared machine. In the Editor test, most of the first filter is formatting the two searchable number columns' text once; setting Searchable = false on number columns nobody searches avoids it, and the stress scene does that. The sort and filter times are measured around the call plus the first read of DisplayedRowCount.
The EditMode suite also asserts that scrolling a warmed 100,000-row table for 600 frames and 100 page jumps makes no GC allocation (Is.Not.AllocatingGCMemory()).
Advice
- Return a stored string from
Textwhen you can; useCacheText(or a number column) when you must build one. - Set
Searchable = falseon columns nobody searches, mostly number columns. - Call
NotifyRowChanged(i)for one changed row andRefresh()only when many rows changed or the sort or filter result may have changed. - Keep
OnBindof custom cells free of allocation. - TextMeshPro costs more than legacy Text when many cells are rebound at once (a full rebind of every visible cell, for example after
Rebuild); scrolling rebinds only the rows that scrolled in.
Domain Reload
Every static field of the package is reset in a RuntimeInitializeOnLoadMethod at SubsystemRegistration: the shared default style, the cached built-in font, the TextMeshPro warning flag and the cached keyboard keys. The table and its events are instance state, so Play mode with Enter Play Mode Options > Reload Domain turned off starts clean. Subscriptions made by your own scripts follow your own scripts' lifetime: unsubscribe in OnDisable as in the example under Events.
Checked on 2026-10-21 in clean projects on Unity 6000.3.12f1 and 6000.0.84f1: three Play sessions in a row with Domain Reload disabled gave the same results, with the package's static state the same at the start of each session.
Platform support and tested on
Data Table is C# on uGUI, so it draws only with uGUI and has no shader or material, so it is intended for every platform uGUI runs on; it was run with the Built-in render pipeline only, and URP and HDRP were not run. What was run is listed here; a platform that is not listed, or a row that says not run, was not run.
| Platform | Status |
|---|---|
| Windows Editor, Unity 6000.3.12f1 | Run on Windows 11 (2026-10-21) in the development project (Built-in pipeline, Input System and Input Manager both active, com.unity.ugui 2.0.0, Input System 1.19.0, TMP Essential Resources imported): 354 of 354 EditMode tests passed. |
| Windows player (Mono), Unity 6000.3.12f1 | Run on Windows 11, Direct3D 12 (2026-10-20, again 2026-10-21), Development build, 1280 x 720: a smoke driver walked the five demo scenes through the public API and the EventSystem (row and header hits, clicks, sorts, filter, selection, resize, adding and removing rows, disabling and enabling the table, a TextMeshPro pass) and passed, with 14 screenshots checked. Input System UI module; clicks simulated inside the engine, not a physical mouse. |
| Windows player (IL2CPP, managed stripping High), Unity 6000.3.12f1 | Run on Windows 11 (2026-10-20, again 2026-10-21), Development build: the same driver passed. |
| Windows player, release build | Run on 2026-10-20 on the first version of the code, before the review fixes: the release build started with the driver inert (no [QA] line in its log). The demo itself was not exercised in a release build. |
| Android (IL2CPP, ARM64 and x86-64, managed stripping High) | Run on x86_64 Android emulators (2026-10-21), Development builds from clean projects: the smoke driver passed on API 36 (Android 16, APK from Unity 6000.3.12f1, built with OpenGL ES 3 only, because the emulator's Vulkan driver crashed inside Unity's graphics thread before any script ran) and on API 24 and API 25 (Android 7.0 and 7.1, APK from Unity 6000.0.84f1 with the default graphics APIs; it ran on OpenGL ES 3). 14 screenshots each; 0 bytes allocated in every measured scrolling frame. Frame times on the emulators are not representative of a device. Not run on a physical device, so touch scrolling and Toggle selection by a real finger are not covered. |
| Clean project, Unity 6000.3.12f1, Built-in pipeline, Input Manager | Run on Windows 11 (2026-10-21): a new project created by Unity 6000.3.12f1 (Built-in pipeline, Input Manager, no TMP Essential Resources), the package installed from a .tgz archive and the Demo sample imported: 348 EditMode tests passed and 6 were skipped (the TextMeshPro cases that need the TMP Essential Resources), 0 failed; the five scenes opened with 0 missing scripts; the Windows player (Mono) smoke passed, with the TextMeshPro request falling back to legacy Text and one warning. |
| Clean project, Unity 6000.3, URP, Input System package only | Not run. |
| Clean project, Unity 6000.0.84f1 | Run on Windows 11 (2026-10-21): the same steps in a new project created by Unity 6000.0.84f1 (Built-in pipeline, Input Manager): 348 passed, 6 skipped, 0 failed; 0 missing scripts; the Windows player (Mono, Direct3D 11) smoke passed. |
| Play mode with Domain Reload disabled | Run on Windows 11 (2026-10-21) in both clean projects: three Play sessions in a row with Domain Reload disabled, playing the sample's stress and CSV scenes; the package's static fields were the same at the start of every session, a value changed on purpose in the shared default style did not survive, and the results matched. |
| Other platforms (macOS, Linux, iOS, WebGL and the rest) | not run |
Also not run: a physical mouse or touch screen, a gamepad, a keyboard layout other than the development machine's, and the Input System keyboard shortcuts on a non-QWERTY layout (TableInput is not covered by the EditMode tests, which cannot read input devices).
Limitations
These are known and stated up front.
- uGUI only. For UI Toolkit, use Unity's
MultiColumnListView. - No in-cell editing, no column reordering by dragging, no grouping or tree rows, no pinned (frozen) columns, no pagination controls, no data binding to databases or web services, no sorting by more than one column, no Edit mode preview, no elastic overscroll.
- All rows have the same height (
rowHeight). - Legacy Text cuts long text at a word boundary with no ellipsis; TextMeshPro shows an ellipsis. Cell text is never wrapped to a second line. Rich text is off.
- Play mode only. The table builds its child objects in Play mode. In Edit mode it is an empty rectangle.
- Needs an EventSystem in the scene and a
GraphicRaycasteron the Canvas. - One table handles its own scrolling. A
ScrollRectaround a table does not receive the wheel or drag events over it. Use one or the other. - Main thread only.
- Column widths are limited to 16 as the lowest minimum and 4096 as the highest width set by
SetColumnWidth. - Number columns format with the invariant culture. For culture-specific numbers or dates, use the text constructor and format in your delegate (with
CacheTexton). - CsvTable shows text. Every cell is a string; only numeric detection is automatic. It does not write files.
API reference
Namespace: Luanrobs.DataTable. Assembly: Luanrobs.DataTable.
If your scripts live in an assembly definition, add a reference to Luanrobs.DataTable.
DataTableView
public sealed class DataTableView : Selectable (component, Add Component > luanrobs > Data Table View; one per GameObject; requires a RectTransform)
| Member | Description |
|---|---|
TableData<TRow> SetData<TRow>(IEnumerable<TRow> rows, IReadOnlyList<TableColumn<TRow>> columns) |
Shows rows; replaces any previous data. Throws ArgumentNullException for null columns, ArgumentException for a null column. Null rows means no rows. |
void ClearData() |
Removes rows and columns. |
void Rebuild() |
Rebuilds the header and the row objects from the current style and column definitions; widths return to the definitions. |
TableColumn GetColumn(int column) |
The definition of a column. |
float GetColumnWidth(int column), void SetColumnWidth(int column, float width) |
Live width of a column; set it. |
int GetDisplayIndex(int rowIndex), int GetRowIndex(int displayIndex) |
Convert between row and display indices (-1 when hidden by the filter). |
void Sort(int column, TableSortDirection direction), void ClearSort() |
Sort by a column, or return to list order. |
bool IsSelected(int rowIndex), void Select(int rowIndex), void SetSelected(int rowIndex, bool selected) |
Selection by row index. |
void SelectAll(), void ClearSelection(), void GetSelectedIndices(List<int> results) |
More selection. |
bool ScrollToRow(int rowIndex, TableScrollAlignment alignment = Nearest) |
Scrolls vertically; false when hidden by the filter. |
string GetCsv(TableCsvScope scope = DisplayedRows, bool includeHeader = true, char separator = ',') |
CSV text. |
void CopyCsvToClipboard(TableCsvScope scope = DisplayedRows, bool includeHeader = true, char separator = ',') |
Puts the same text on the system clipboard. |
event Action<int> RowClicked, event Action<int> RowActivated, event Action SelectionChanged, event Action<int, TableSortDirection> SortChanged, event Action<int, float> ColumnResized |
See Events. |
DataTableStyle Style, TableSelectionMode SelectionMode, bool ShowHeader, bool AllowSorting, bool AllowColumnResize, bool DragToScroll, bool KeyboardNavigation, float ScrollWheelRows, bool EscapeCsvFormulas |
See Options. |
string FilterText, Vector2 ScrollPosition |
Settable state. |
bool HasData, int RowCount, int DisplayedRowCount, int ColumnCount, int LiveRowCount, int SortColumn, TableSortDirection SortDirection, int SelectedCount, int SelectedIndex, Vector2 MaxScrollPosition |
Read-only state. |
OnScroll, OnInitializePotentialDrag, OnBeginDrag, OnDrag, OnEndDrag, OnSubmit, OnMove |
EventSystem callbacks. Called by the EventSystem, not by your code. |
TableData<TRow>
public sealed class TableData<TRow>. Returned by SetData; its constructor is internal. Members are listed in Changing the data: View, IsAttached, Rows, Columns, Count, the indexer, RowFilter, SetRows, Add, AddRange, Insert, RemoveAt, Remove, Clear, IndexOf, NotifyRowChanged, Refresh, GetSelectedRows, TryGetSelectedRow.
TableColumn and TableColumn<TRow>
public abstract class TableColumn has Header, Width, MinWidth, Flex, Alignment, Resizable, Searchable, CacheText and the read-only Sortable (true when Compare is set) and HasCustomCell. public sealed class TableColumn<TRow> : TableColumn adds Text, Compare, Cell and the three constructors in Rows and columns.
TableCell and TableCell<TRow>
public abstract class TableCell and public abstract class TableCell<TRow> : TableCell. Their constructors are internal, so derive from TableCell<TRow>. Members in Cells and custom cells: Table, RectTransform, Style, ColumnIndex, RowIndex, IsSelected, IsHovered, AddLabel(), OnCreate(), OnBind(TRow) (abstract), OnRowStateChanged(), OnDispose().
TableLabel
public sealed class TableLabel, created by TableCell.AddLabel(). RectTransform, Graphic, string Text (setting the text already shown does nothing), Color Color, TableAlignment Alignment, int FontSize, FontStyle FontStyle.
DataTableStyle
public sealed class DataTableStyle : ScriptableObject. Fields in Styles and text; static DataTableStyle Default.
CsvTable
public sealed class CsvTable : MonoBehaviour (Add Component > luanrobs > CSV Table; requires a DataTableView; one per GameObject). TextAsset Csv, char Separator, bool FirstRowIsHeader, float ColumnWidth, DataTableView Table, TableData<string[]> Data, void Load(string csvText), void Reload().
Enums
| Enum | Values |
|---|---|
TableSelectionMode |
None, Single, Multiple, Toggle |
TableSortDirection |
None, Ascending, Descending |
TableAlignment |
Left, Center, Right |
TableTextRenderer |
LegacyText, TextMeshPro |
TableCsvScope |
AllRows, DisplayedRows, SelectedRows |
TableScrollAlignment |
Nearest, Top, Center, Bottom |
Troubleshooting and FAQ
The table is empty in the Scene view or in Edit mode
By design: the table builds its child objects in Play mode only. In Edit mode it is an empty rectangle. Data set in Edit mode appears when Play mode starts.
The table is empty in Play mode
- Check that
SetDatawas called, and with rows:table.HasDataandtable.RowCount. - Check that the table object has a size. A table with a zero-height rectangle shows no rows (
LiveRowCountstays 0). - Check
FilterText: a filter that matches nothing shows an empty table.DisplayedRowCountsays how many rows pass. - Look at the Console for exceptions from your
Textdelegate orCellfactory; the table logs them once per column.
Clicks, the wheel and sorting do nothing
The table needs an EventSystem in the scene and a GraphicRaycaster on its Canvas, like a Button. Create a Canvas from the GameObject menu and Unity adds both. Also check that Interactable is on, that nothing transparent with Raycast Target on sits above the table, and, for keys, that the table has focus (click it first) and Keyboard Navigation is on.
Header clicks do not sort a column
The column needs a Compare (text and number columns have one; a custom cell column needs you to set it), Allow Sorting must be on, and the column must not have been given Compare = null.
Text is missing or shows only part of a line
With legacy Text, the label is one line tall; a rowHeight below fontSize * 1.3 can hide the text entirely. Raise rowHeight in the style or lower fontSize. A text that does not fit is cut at a word boundary without an ellipsis; widen the column or use TextMeshPro, which shows an ellipsis.
TextMeshPro text is missing, and the Console shows a warning
The style asks for TextMeshPro but the TMP Settings asset is missing or no TMP font asset was found (the warning says which), so the table used legacy Text. Import the TMP Essential Resources (Window > TextMeshPro > Import TMP Essential Resources); they are needed even when you assign your own font asset to Tmp Font in the style.
My custom cell shows the wrong row, or old data
The cell is reused for different rows. Draw everything from the row passed to OnBind and reset any per-row state there; keep no state of a previous row. The table binds the cell again after every sort, filter and row change.
I changed a field of a row and the table did not change
The table cannot see changes inside your row objects. Call data.NotifyRowChanged(rowIndex) for one row, or data.Refresh() for many (or when the sort or filter result may have changed). If a number column's text is cached, these calls drop the cache.
I changed a style or a column and nothing happened
Call table.Rebuild() after changing a style asset's values or a column definition at runtime. Assigning a different style asset to table.Style rebuilds on its own.
My ScrollRect and the table fight over the wheel
Do not put a table inside a ScrollRect: the table scrolls itself and takes the wheel and drag events over it. Give the table the size you want instead. The page around it can still use a ScrollRect for its other parts.
The wheel does not scroll sideways
Hold Shift while turning the wheel, or use a horizontal wheel or a sideways trackpad swipe. Without Shift a vertical wheel scrolls vertically. With a keyboard or gamepad, Left and Right scroll sideways while the table has focus.
Ctrl+C copies nothing
Ctrl+C (Command+C) copies the selected rows, so select some rows first, and the table needs focus. It writes tab-separated text without the header line. For other formats, call GetCsv or CopyCsvToClipboard yourself.
The first filter on a large list is slow
The first filter formats and caches the text of every searchable column, including number columns. Set Searchable = false on columns nobody searches.
The numbers show a dot or a comma that differs from my language
Number columns format with the invariant culture. Use the text constructor and format with the culture you want in the delegate, with CacheText on.
A CSV column with decimal commas sorts in the wrong order
Set Separator to the character the file really uses (; for most spreadsheets set to European languages). Decimal commas are read only when the separator is not a comma. A column that mixes 1.5 and 1,5 in the same file is a text column.
Scrolling allocates memory in my project
Once the row objects exist and the number texts are cached (measured on a second pass over the same range), the table allocates nothing while it only scrolls. Look at your own code: a Text delegate that builds a string on every call (turn on CacheText), an OnBind that allocates, or a handler of RowClicked that does. The Profiler's GC Alloc column, deep profile off, shows the call.
The sample's 00 Menu says a scene is missing
The menu loads scenes by name. Add all five scenes to the Scene List (File > Build Profiles) with 00 Menu first; this is needed in the Editor as well as in a build.
Support
Email: luanrobs@gmail.com
When reporting a problem, please include your Unity version, the platform (device model and OS version), whether you use legacy Text or TextMeshPro, the input system in use, and the Console or Player log output.
Product page: https://luanrobs.com/data-table/
Manual online: https://luanrobs.com/data-table/docs/
Changelog: https://luanrobs.com/data-table/changelog/
I maintain and support this package myself. If it saves you time, a review on the Asset Store helps a lot. Thank you.