Skip to content

SortButton

A heading that sorts a list, the way a table’s header does, for lists that are not tables: a grid of emote cards, a row of shop items, a friends list drawn your own way. Press it to sort by that column, again to flip the order, and a third time to stop sorting by it. DataGrid’s headers are SortButtons.

It works with useSort or useTable. With multi on, several columns sort together: the first pressed leads, and each one pressed after it breaks the ties of the ones before. A small number shows each column’s place while more than one sorts.

SortButton exampleSortButton example
local RARITY = { Common = 1, Rare = 2, Epic = 3, Legendary = 4 }

local emotes = Lucy.useSort({
    data = owned,
    columns = {
        { key = "name", header = "Name" },
        { key = "style", header = "Style" },
        { id = "rarity", header = "Rarity", get = function(emote) return RARITY[emote.rarity] end, descFirst = true },
    },
    sorting = { { id = "rarity", desc = true } },
    multi = true,
})

Lucy.Stack.new({
    direction = "horizontal",
    gap = "Space3",
    children = {
        Lucy.SortButton.new({ sort = emotes, column = "name" }),
        Lucy.SortButton.new({ sort = emotes, column = "style" }),
        Lucy.SortButton.new({ sort = emotes, column = "rarity" }),
    },
})

Props

PropTypeDefaultState keyWhat it does
sorttableWhat it sorts: the result of useSort or useTable
columnstringThe id of the column it sorts
textstringthe column’s header, or "" with childrenThe label
childrentableAnything after the label in its slot, before the chevron. Muted until it sorts, then bright, as the label
alignstring"left"left, center or right
disabledbooleanfalseyesStops presses. On by itself for a column that does not sort
onClickfunctionCalled with the handle after it sorts
sizeUDim2as wide as its text, ControlSm tallIts size
visiblebooleantrueyesShows or hides it

It also takes the props every component takes.

While its column sorts, the label is bright and lucy:chevron-up or lucy:chevron-down shows the direction. To use your own icons, see Icons Lucy draws.

Methods and events

NameWhat it does
button:click()What a press does: sorts, then calls onClick
button.ActivatedA signal fired on each press
button.labelThe label
button.iconThe direction Icon
button.priorityThe label with the column’s place in the sort

A press reports activate, for game sounds.

Preview

In Studio, from the command bar: Lucy.Preview.show("SortButton").