deploy: 5a1ec672a7
This commit is contained in:
@@ -1,32 +1,120 @@
|
||||
# Table
|
||||
_This is the table class. It provides a sortable data grid with customizable columns,_
|
||||
_row selection, and scrolling capabilities._
|
||||
_This is the table class. It provides a sortable data grid with customizable columns, row selection, and scrolling capabilities. Built on Collection for consistent item management._
|
||||
|
||||
Extends: `VisualElement`
|
||||
Extends: `Collection`
|
||||
|
||||
## Usage
|
||||
```lua run
|
||||
local people = container:addTable():setWidth(40)
|
||||
```
|
||||
|
||||
```lua run
|
||||
people:setColumns({{name="Name",width=12}, {name="Age",width=10}, {name="Country",width=15}})
|
||||
```
|
||||
|
||||
```lua run
|
||||
people:addRow("Alice", 30, "USA"):addRow("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|
|
||||
|headerColor|color|blue|Color of the column headers|
|
||||
|selectedColor|color|lightBlue|Background color of selected row|
|
||||
|gridColor|color|gray|Color of grid lines|
|
||||
|sortDirection|string|"asc"|Sort direction ("asc" or "desc")|
|
||||
|scrollOffset|number|0|Current scroll position|
|
||||
|customSortFunction|table|{}|Custom sort functions for columns|
|
||||
|offset|number|0|Scroll offset for vertical scrolling|
|
||||
|showScrollBar|boolean|true|Whether to show the scrollbar when items exceed height|
|
||||
|scrollBarSymbol|string|"|" Symbol used for the scrollbar handle|
|
||||
|scrollBarBackground|string|"\127"|Symbol used for the scrollbar background|
|
||||
|scrollBarColor|color|lightGray|Color of the scrollbar handle|
|
||||
|scrollBarBackgroundColor|color|gray|Background color of the scrollbar|
|
||||
|
||||
## Events
|
||||
|
||||
|Event|Parameters|Description|
|
||||
|---|---|---|
|
||||
|onRowSelect|`rowIndex number, row table`|Fired when a row is selected|
|
||||
|
||||
## Functions
|
||||
|
||||
|Method|Returns|Description|
|
||||
|---|---|---|
|
||||
|[Table:addRow](#table-addrow-any)|Table|Adds a new row with cell values|
|
||||
|[Table:removeRow](#table-removerow-rowindex)|Table|Removes a row at the specified index|
|
||||
|[Table:getRow](#table-getrow-rowindex)|row|Gets the row data at the specified index|
|
||||
|[Table:updateCell](#table-updatecell-rowindex-colindex-value)|Table|Updates a cell value at row and column|
|
||||
|[Table:getSelectedRow](#table-getselectedrow)|row|Gets the currently selected row data|
|
||||
|[Table:clearData](#table-cleardata)|Table|Removes all rows from the table|
|
||||
|[Table:addColumn](#table-addcolumn-name-width)|Table|Adds a new column to the table|
|
||||
|[Table:addData](#table-adddata-any)|Table|Adds a new row of data to the table|
|
||||
|[Table:setColumnSortFunction](#table-setcolumnsortfunction-columnindex-sortfn)|Table|Sets a custom sort function for a column|
|
||||
|[Table:setFormattedData](#table-setformatteddata-displaydata-sortdata)|Table|Adds formatted data with raw sort values|
|
||||
|[Table:setData](#table-setdata-rawdata-formatters)|Table|Sets table data with optional column formatters|
|
||||
|[Table:sortData](#table-sortdata-columnindex-fn)|Table|Sorts the table data by the specified column|
|
||||
|[Table:getData](#table-getdata)|table|Gets all rows as array of cell arrays|
|
||||
|[Table:sortByColumn](#table-sortbycolumn-columnindex-fn)|Table|Sorts the table data by the specified column|
|
||||
|[Table:onRowSelect](#table-onrowselect-callback)|Table|Registers a callback when a row is selected|
|
||||
|
||||
## Table:addRow(any)
|
||||
|
||||
Adds a new row to the table
|
||||
|
||||
### Parameters
|
||||
* `any` `The` cell values for the new row
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
### Usage
|
||||
```lua run
|
||||
table:addRow("Alice", 30, "USA")
|
||||
```
|
||||
|
||||
## Table:removeRow(rowIndex)
|
||||
|
||||
Removes a row by index
|
||||
|
||||
### Parameters
|
||||
* `rowIndex` `number` The index of the row to remove
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
## Table:getRow(rowIndex)
|
||||
|
||||
Gets a row by index
|
||||
|
||||
### Parameters
|
||||
* `rowIndex` `number` The index of the row
|
||||
|
||||
### Returns
|
||||
* `row` `The` row data or nil
|
||||
|
||||
## Table:updateCell(rowIndex, colIndex, value)
|
||||
|
||||
Updates a specific cell value
|
||||
|
||||
### Parameters
|
||||
* `rowIndex` `number` The row index
|
||||
* `colIndex` `number` The column index
|
||||
* `value` `any` The new value
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
## Table:getSelectedRow()
|
||||
|
||||
Gets the currently selected row
|
||||
|
||||
### Returns
|
||||
* `row` `The` selected row or nil
|
||||
|
||||
## Table:clearData()
|
||||
|
||||
Clears all table data
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
## Table:addColumn(name, width)
|
||||
|
||||
@@ -34,17 +122,7 @@ Adds a new column to the table
|
||||
|
||||
### Parameters
|
||||
* `name` `string` The name of the column
|
||||
* `width` `number` The width of the column
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
## Table:addData(any)
|
||||
|
||||
Adds a new row of data to the table
|
||||
|
||||
### Parameters
|
||||
* `any` `The` data for the new row
|
||||
* `width` `number|string` The width of the column (number, "auto", or "30%")
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
@@ -60,29 +138,30 @@ Sets a custom sort function for a specific column
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
## Table:setFormattedData(displayData, sortData)
|
||||
|
||||
Adds data with both display and sort values
|
||||
|
||||
### Parameters
|
||||
* `displayData` `table` The formatted data for display
|
||||
* `sortData` `table` The raw data for sorting (optional)
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
## Table:setData(rawData, formatters)
|
||||
|
||||
Set data with automatic formatting
|
||||
|
||||
### Parameters
|
||||
* `rawData` `table` The raw data array
|
||||
* `formatters` `table` Optional formatter functions for columns {[2] = function(value) return value end}
|
||||
* `rawData` `table` The raw data array (array of row arrays)
|
||||
* `formatters` `table` ? Optional formatter functions for columns {[2] = function(value) return value end}
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
## Table:sortData(columnIndex, fn)
|
||||
### Usage
|
||||
```lua run
|
||||
table:setData({{...}}, {[1] = tostring, [2] = function(age) return age.."y" end})
|
||||
```
|
||||
|
||||
## Table:getData()
|
||||
|
||||
Gets all table data
|
||||
|
||||
### Returns
|
||||
* `table` `data` Array of row cell arrays
|
||||
|
||||
## Table:sortByColumn(columnIndex, fn)
|
||||
|
||||
Sorts the table data by column
|
||||
|
||||
@@ -92,3 +171,13 @@ Sorts the table data by column
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
## Table:onRowSelect(callback)
|
||||
|
||||
Registers callback for row selection
|
||||
|
||||
### Parameters
|
||||
* `callback` `function` The callback function(rowIndex, row)
|
||||
|
||||
### Returns
|
||||
* `Table` `self` The Table instance
|
||||
|
||||
Reference in New Issue
Block a user