Skip to content

Table

This is the table class. It provides a sortable data grid with customizable columns,row selection, and scrolling capabilities.

Extends: VisualElement

Properties

PropertyTypeDefaultDescription
columnstable{}List of column definitions with {name, width} properties
datatable{}The table data as array of row arrays
headerColorcolorblueColor of the column headers
selectedColorcolorlightBlueBackground color of selected row
gridColorcolorgrayColor of grid lines
sortDirectionstring"asc"Sort direction ("asc" or "desc")
scrollOffsetnumber0Current scroll position
customSortFunctiontable{}Custom sort functions for columns

Functions

MethodReturnsDescription
Table:addColumnTableAdds a new column to the table
Table:addDataTableAdds a new row of data to the table
Table:setColumnSortFunctionTableSets a custom sort function for a column
Table:setFormattedDataTableAdds formatted data with raw sort values
Table:setDataTableSets table data with optional column formatters
Table:sortDataTableSorts the table data by the specified column

Table:addColumn(name, width)

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

Returns

  • Table self The Table instance

Table:setColumnSortFunction(columnIndex, sortFn)

Sets a custom sort function for a specific column

Parameters

  • columnIndex number The index of the column
  • sortFn function Function that takes (rowA, rowB) and returns comparison result

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

Returns

  • Table self The Table instance

Table:sortData(columnIndex, fn)

Sorts the table data by column

Parameters

  • columnIndex number The index of the column to sort by
  • fn function ? Optional custom sorting function

Returns

  • Table self The Table instance

Released under the MIT License.