1.6 KiB
1.6 KiB
Table : VisualElement
This is the table class. It provides a sortable data grid with customizable columns, row selection, and scrolling capabilities.
Usage
local people = container:addTable():setWidth(40)
people:setColumns({{name="Name",width=12}, {name="Age",width=10}, {name="Country",width=15}})
people:setData({{"Alice", 30, "USA"}, {"Bob", 25, "UK"}})
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| columns | table | {} | List of column definitions with {name, width} properties |
| data | table | {} | The table data as array of row arrays |
| selectedRow | number? | nil | Currently selected row index |
| headerColor | color | blue | Color of the column headers |
| selectedColor | color | lightBlue | Background color of selected row |
| gridColor | color | gray | Color of grid lines |
| sortColumn | number? | nil | Currently sorted column index |
| sortDirection | string | "asc" | Sort direction ("asc" or "desc") |
| scrollOffset | number | 0 | Current scroll position |
Functions
| Method | Returns | Description |
|---|---|---|
| Table:sortData | Table | Sorts the table data by the specified column |
Protected Functions
| Method | Returns | Description |
|---|---|---|
| Table:init | Table | Initializes the Table instance |
| Table:mouse_click | boolean | Handles header clicks for sorting and row selection |
| Table:mouse_scroll | boolean | Handles scrolling through the table data |
| Table:render | - | Renders the table with headers, data and scrollbar |
Table:sortData(columnIndex, fn)
Sorts the table data by column
Parameters
columnIndexnumberThe index of the column to sort byfnfunction?Optional custom sorting function
Returns
TableselfThe Table instance