Table
Rows and columns: a leaderboard, a friends list, an inventory, match history. Table draws the rows you give it in the order you give them. For headers the player can press to sort, use DataGrid.

Lucy.Table.new({
rows = {
{ rank = 1, name = "Nova", hype = 9840 },
{ rank = 2, name = "DJ Lucy", hype = 9125 },
{ rank = 3, name = "Kai", hype = 8410 },
{ rank = 4, name = "Juno", hype = 7360 },
},
rowId = function(dancer) return dancer.name end,
columns = {
{ key = "rank", header = "#", width = 56, align = "center" },
{ key = "name", header = "Dancer", width = { fill = 2 } },
{ key = "hype", header = "Hype", width = { fill = 1 }, align = "right" },
},
highlight = function(dancer) return dancer.name == app.state:get("player.name") end,
maxHeight = 360,
Parent = parent,
})
Props
| Prop | Type | Default | State key | What it does |
|---|---|---|---|---|
columns | table | The columns, see Columns | ||
rows | array, ref, computed or getter | The rows, any tables you like | ||
rowId | function | the position | Gives each row an id, so updates change cells instead of rebuilding rows | |
rowHeight | number | control height | Each row's height in pixels | |
highlight | function | Return true for rows to pick out, such as the player's own | ||
striped | boolean | false | Shades every other row | |
onRowClick | function | Called with (row, index). Rows become buttons the player can select | ||
headerCell | function | Draws a header cell in place of its text: called with (column, align), returns a component, an Instance or text. DataGrid draws its sort buttons this way | ||
empty | string | Shown when there are no rows | ||
maxHeight | number | The body scrolls past this many pixels | ||
virtual | boolean | false | Builds only the rows near the view, see Long lists | |
onEndReached | function | Called when the player scrolls near the end, see Long lists | ||
size | UDim2 | full width | With a height, the body fills what the header leaves | |
visible | boolean | true | yes | Shows or hides it |
It also takes the props every component takes.
Columns
| Field | What it does |
|---|---|
key | The field to show, and the column's id |
id | The column's id, when it has no key |
get | A function from the row to the value, instead of key |
header | The header text |
width | Pixels, or { fill = n } for a share of the width the fixed columns leave. { fill = 1 } when left out |
align | left, center or right |
cell | A function that draws the cell, see below |
A cell shows the value as text. For anything else, give the column a cell
function. It gets ctx and returns an instance, a component or text:
ctx.row(): the row, kept up to date as your data changesctx.value(): the column's value for that row, also kept up to datectx.column: the column
{
key = "userId",
header = "",
width = 48,
cell = function(ctx)
return Lucy.Avatar.new({ userId = ctx.value, size = "sm" })
end,
}
Pass ctx.value or ctx.row themselves (not their results) to a component's
props, and the cell follows the data.
Updating rows
Give new data whenever it changes: a new array, a ref you set, or a getter.
Rows are matched by rowId, so a changed score changes one cell, and a row that
moves up the board moves rather than being rebuilt. The header stays put while
the body scrolls.
Long lists
With virtual = true and a rowHeight, the body is as tall as every row, but
only the rows on screen and a few either side exist. They are built as they
come near the view and removed as they leave, so a board of 10,000 players
costs about what twenty cost.
onEndReached is called when the player scrolls within a few rows of the end,
once for each row count. Load the next rows and add them to your data, and it
is ready to fire again:
local dancers = Lucy.ref({})
Lucy.Table.new({
rows = dancers,
rowId = function(dancer) return dancer.userId end,
columns = columns,
virtual = true,
rowHeight = 40,
maxHeight = 400,
onEndReached = function()
local more = fetchNextDancers(#dancers())
local all = table.clone(dancers())
table.move(more, 1, #more, #all + 1, all)
dancers(all)
end,
})
Gamepad
With onRowClick, each row can be selected and pressed. Without it, rows are
not selectable, and the body itself can be selected so the player can scroll it.
Preview
In Studio, from the command bar: Lucy.Preview.show("Table").