A collection of utility functions that make it easier to work with table data.
Methods
(static) getCellData(column, rowData, rowNumber, tableData, columns) → {Any}
Gets the value of a cell given the row data. If column.value is a function, it gets called, otherwise it is interpreted as a key to rowData. If column.value is not defined, column.id is used as a key to rowData.
Parameters:
Name | Type | Description |
---|---|---|
column |
Object | The column definition |
rowData |
Object | The data for the row |
rowNumber |
Number | The number of the row |
tableData |
Array.<Object> | The array of data for the whole table |
columns |
Array.<Object> | The column definitions for the whole table |
Returns:
The value for this cell
- Type
- Any
(static) getColumnById(columns, columnId) → {Object}
Gets a column from the column definitions based on its ID
Parameters:
Name | Type | Description |
---|---|---|
columns |
Array.<Object> | The column definitions for the whole table |
columnId |
String | the |
Returns:
The column definition
- Type
- Object
(static) getSortComparator(type) → {function}
Gets the comparator function to use based on the type of data the column represents. These comparator functions expect the data to be presented as { index, sortValue }. sortValue is used to determine the order.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | the DataType the column represents |
Returns:
the comparator for sort
- Type
- function
(static) getSortValue(column, rowData, rowNumber, tableData, columns) → {Any}
Gets the sort value for a cell by first computing the cell data. If no sortValue function is provided on the column, the cellData is returned.
Parameters:
Name | Type | Description |
---|---|---|
column |
Object | The column definition |
rowData |
Object | The data for the row |
rowNumber |
Number | The number of the row |
tableData |
Array.<Object> | The array of data for the whole table |
columns |
Array.<Object> | The column definitions for the whole table |
Returns:
The sort value for this cell
- Type
- Any
(static) getSortValueFromCellData(cellData, column, rowData) → {Any}
Gets the sort value of a cell given the cell data and row data. If no sortValue function is provided on the column, the cellData is returned.
Parameters:
Name | Type | Description |
---|---|---|
cellData |
Object | The cell data |
column |
Object | The column definition |
rowData |
Object | The data for the row |
Returns:
The sort value for this cell
- Type
- Any
(static) renderCell(cellData, column, rowData, rowNumber, tableData, columns) → {Renderable}
Renders a cell's contents based on the renderer function. If no renderer is provided, it just returns the raw cell data. In such cases, the user should take care that cellData can be rendered directly.
Parameters:
Name | Type | Description |
---|---|---|
cellData |
Any | The data for the cell |
column |
Object | The column definition |
rowData |
Object | The data for the row |
rowNumber |
Number | The number of the row |
tableData |
Array.<Object> | The array of data for the whole table |
columns |
Array.<Object> | The column definitions for the whole table |
Returns:
The contents of the cell
- Type
- Renderable
(static) sortData(data, columnId, sortDirection, columns) → {Array.<Object>}
Sorts the data based on sort value and column type. Uses a stable sort by keeping track of the original position to break ties unless the data is already sorted, in which case it just reverses the array.
Parameters:
Name | Type | Description |
---|---|---|
data |
Array.<Object> | the array of data for the whole table |
columnId |
String | the column ID of the column to sort by |
sortDirection |
Boolean | The direction to sort in |
columns |
Array.<Object> | The column definitions for the whole table |
Returns:
The sorted data
- Type
- Array.<Object>
(static) validateColumns(columns) → {void}
Checks an array of column definitions to see if there are any issues. Checks if
- multiple columns have the same ID
Typically only used in development.
Parameters:
Name | Type | Description |
---|---|---|
columns |
Array.<Object> | The column definitions for the whole table |
Returns:
- Type
- void
(inner) alreadySorted(sortDirection, data, comparator) → {Boolean}
Helper function to test if an array is already sorted
Parameters:
Name | Type | Description |
---|---|---|
sortDirection |
Boolean | The direction to check if it is sorted in |
data |
Array | The data to check |
comparator |
function | The comparator to use |
Returns:
True if already sorted, false otherwise
- Type
- Boolean