3.0 KiB
3.0 KiB
Table : VisualElement
This is the table class. It provides a sortable data grid with customizable columns, row selection, and scrolling capabilities.
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.new | Table | Creates a new Table instance |
| 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:setColumns | Table | Sets the table columns configuration |
| Table:setData | Table | Sets the table data |
| Table:sortData | Table | Sorts the table data by the specified column |
Table.new()
Creates a new Table instance
Returns
TableselfThe newly created Table instance
Usage
local table = Table.new()
Table:init(props, basalt)
Initializes the Table instance
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Returns
TableselfThe initialized instance
Table:mouse_click(button, x, y)
Handles mouse click events
Parameters
buttonnumberThe button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanhandledWhether the event was handled
Table:mouse_scroll(direction, x, y)
Handles mouse scroll events
Parameters
directionnumberThe scroll direction (-1 up, 1 down)xnumberThe x position of the scrollynumberThe y position of the scroll
Returns
booleanhandledWhether the event was handled
Table:render()
Renders the table
Table:setColumns(columns)
Sets the table columns
Parameters
columnstable[]Array of column definitions {name="Name", width=10}
Returns
TableselfThe Table instance
Usage
table:setColumns({{name="ID", width=4}, {name="Name", width=10}})
Table:setData(data)
Sets the table data
Parameters
datatable[]Array of row data arrays
Returns
TableselfThe Table instance
Usage
table:setData({{"1", "Item One"}, {"2", "Item Two"}})
Table:sortData(columnIndex)
Sorts the table data by column
Parameters
columnIndexnumberThe index of the column to sort by
Returns
TableselfThe Table instance