API / geotoolkit / data / DataTable / DataTable
Define a data table as a collection of data series defined as columns in the table. This code is inspired by google table.
The data table can be read only, which means that each column is immutable, but it is still possible to add or remove columns.
Example
const datatable1 = new DataTable({
cols: [
{name: 'col1', type: 'string'},
{name: 'col2', type: 'number'}
]
});
const datatable2 = new DataTable<number>({
cols: [
{name: 'col1', type: 'number'},
{name: 'col2', type: 'number'}
]
});↳
DataTable
Constructors
Methods
Methods
▸ addColumn(column): DataTable
Adds a new column to the data table.
Example
// creating common column
datatable.addColumn({ 'name': 'col4', 'type': 'number', 'data': [1, 2, 3, 4] });Example
// creating calculated column
const table = new DataTable<number>({'cols': [
{'name': 'alfa', 'type': 'number', 'data': [1, 4, 6, 7]},
{'name': 'beta', 'type': 'number', 'data': [0, 1, 2, 3]}
]});
table.addColumn( {
'name': 'calculated',
'sources': [table.getColumnByName('alfa'), table.getColumnByName('beta')],
'formula': '2 * alfa + beta'
});| Name | Type | Description |
|---|---|---|
column | Column | a DataSeries object or a object containing descriptions. |
this
▸ addRow(cellArray, ignoreMissingValue?): DataTable
Adds a new row to the data table.
Example
// add a new row to a four-column data table
datatable.addRow([10, 20, 30, 50]);| Name | Type | Description |
|---|---|---|
cellArray | any[] | array of cells |
Optional ignoreMissingValue | boolean | ignore missing value |
this
▸ addRows(rowsArray, ignoreMissingValue?): DataTable
Adds new rows to the data table. This method can be called to create new empty rows, or with data used to populate the rows
Example
// add two rows to a three-column data table
datatable.addRows([[10, 20, 30], [50, 70, 100]]);| Name | Type | Description |
|---|---|---|
rowsArray | number | any[] | rows data or a number of empty rows to add |
Optional ignoreMissingValue | boolean | ignore missing value |
this
▸ clear(): DataTable
Clears all cells of the data table.
this
▸ clone(copyData?): DataTable
Returns a clone of the data table.
| Name | Type | Description |
|---|---|---|
Optional copyData | boolean | copy data |
clone
▸ dispose(): void
Dispose.
void
▸ fillTable(columnsArray): DataTable
Fills data table with specified array of column data.
Example
// fill table with two columns
datatable.fillTable([[10, 20, 30, 50], [30, 40, 30, 50]]);| Name | Type | Description |
|---|---|---|
columnsArray | any[] | array of values by column |
this
▸ getClassName(): string
string
AbstractDataTable.getClassName
▸ getColumn(columnIndex): DataSeries<any>
Returns column by index
| Name | Type | Description |
|---|---|---|
columnIndex | number | index of column |
DataSeries<any>
DataSeries
▸ getColumnById(id): DataSeries<any>
Returns column by specified identifier. If multiple columns have the same identifier, the first one will be returned.
| Name | Type | Description |
|---|---|---|
id | string | number | identifier of the column |
DataSeries<any>
a column
AbstractDataTable.getColumnById
▸ getColumnByName(name): DataSeries<any>
Returns column by specified name. If multiple columns have the same name, the first one will be returned.
| Name | Type | Description |
|---|---|---|
name | string | name of the column |
DataSeries<any>
a column
AbstractDataTable.getColumnByName
▸ getColumnProperties(columnIndex): Record<string, any>
Returns the map of all properties of specified column.
| Name | Type | Description |
|---|---|---|
columnIndex | number | index of the column |
Record<string, any>
AbstractDataTable.getColumnProperties
▸ getMetaData(): Record<string, any>
Returns the map of all meta data of the data table. This method returns the reference to the meta data.
Record<string, any>
▸ getName(): string
Returns table name
string
▸ getNumberOfColumns(): number
Returns the number of columns in the data table.
number
number of columns
AbstractDataTable.getNumberOfColumns
▸ getNumberOfRows(): number
Returns number of rows.
number
AbstractDataTable.getNumberOfRows
▸ getRow(rowIndex, cells?): any[]
Returns an array of values at specified row index.
| Name | Type | Description |
|---|---|---|
rowIndex | number | index of the row. It should be a number greater than or equal to zero, and less than the number of rows as returned by the getNumberOfRows() method. |
Optional cells | any[] | optional array to fill values |
any[]
array of values
▸ getValue(rowIndex, columnIndex): any
Return the value of a cell.
| Name | Type | Description |
|---|---|---|
rowIndex | number | index of the row. It should be a number greater than or equal to zero, and less than the number of rows as returned by the getNumberOfRows() method. |
columnIndex | number | index of the column. should be a number greater than or equal to zero, and less than the number of columns as returned by the getNumberOfColumns() method. |
any
▸ hasEventListener(type, callback?): boolean
Check if a list of event listeners for this type contains this listener
| Name | Type | Description |
|---|---|---|
type | string | type of event or property |
Optional callback | Function | to be called, if null, check if any callback is registered |
boolean
AbstractDataTable.hasEventListener
▸ indexOfColumn(column): number
Returns the index of specified column.
| Name | Type | Description |
|---|---|---|
column | DataSeries<any> | column |
number
index
AbstractDataTable.indexOfColumn
▸ insertColumn(columnIndex, column): DataTable
Inserts a column at specified index.
| Name | Type | Description |
|---|---|---|
columnIndex | number | column index to insert |
column | Column | column |
this
▸ insertRow(rowIndex, cellArray): DataTable
Insert a row at the specified row index
Example
// insert a row at index 10 to a four-column data table
datatable.insertRow(10, [10, 20, 30, 50]);| Name | Type | Description |
|---|---|---|
rowIndex | number | index number where to insert the new row |
cellArray | any[] | array of cells |
this
▸ isDisposed(): boolean
Returns whether this object has been disposed
boolean
▸ isSilent(): boolean
Return true if the event dispatcher doesn't notify any events
boolean
▸ notify<E>(type, source, args?): DataTable
Notify listeners
| Name | Type |
|---|---|
E | extends string |
| Name | Type | Description |
|---|---|---|
type | E | event types |
source | DataTable | of the event |
Optional args | EventMap[E] | arguments of the event |
this
▸ off<E>(type?, callback?): DataTable
Detach listener on event. Calling .off() with no arguments removes all attached listeners. Calling .off(type) with no callback removes all attached listeners for specific type.
| Name | Type |
|---|---|
E | extends string |
| Name | Type | Description |
|---|---|---|
Optional type | E | type of the event |
Optional callback | (eventType: E, sender: DataTable, args: EventMap[E]) => void | function to be called |
this
▸ on<E>(type, callback): DataTable
Attach listener on event that will be called whenever the specified event is delivered to the target
If the callback function is already in the list of event listeners for this target, the function is not added a second time.
If a particular anonymous function is in the list of event listeners registered for a certain target, and then later in the code, an identical anonymous function is given in an "on" call, the second function will also be added to the list of event listeners for that target.
| Name | Type |
|---|---|
E | extends string |
| Name | Type | Description |
|---|---|---|
type | E | type of event or property |
callback | (eventType: E, sender: DataTable, args: EventMap[E]) => void | to be called |
this
▸ query(): QueryBuilder<any>
Query data item and child items by different conditions
Example
// Select by function
table.query()
.where( (item) => return item.getUri() === 'itemuri')
.select(function(item) {
founditem = item;
});Example
// Select by expression
table.query()
.where('item => uri(item) == "itemuri"')
.select((item) => {
founditem = item;
});QueryBuilder<any>
query object which has methods 'where' tp specify conditions, 'select' to run query, 'selectToArray' select results to array Expressions syntax: "item => expression", where expression:
- logical and arithmetic operators
- embedded functions: name(item) - gets name of the data object url(item) - gets url of the data object type(item) - gets type of the data object
▸ removeColumns(columnIndex, numberOfColumns?): DataTable
Removes column(s) at the specified index.
| Name | Type | Description |
|---|---|---|
columnIndex | number | column index to remove |
Optional numberOfColumns | number | number of columns to remove |
this
▸ removeRows(rowIndex, numberOfRows?): DataTable
Removes row(s) from all columns in the data table.
| Name | Type | Description |
|---|---|---|
rowIndex | number | the index number where to start removing the rows |
Optional numberOfRows | number | the amount of rows to remove |
this
▸ setColumnProperties(columnIndex, properties): DataTable
Sets properties of specified column.
| Name | Type | Description |
|---|---|---|
columnIndex | number | index of the column |
properties | Record<string, any> | a map of properties for the specified column. All properties will be merged with existing ones. |
this
▸ setColumnValues(columnIndex, cellArray): DataTable
Sets an array of values at specified column index.
| Name | Type | Description |
|---|---|---|
columnIndex | number | index of the column |
cellArray | any[] | array of values to set |
this
▸ setMetaData(meta): DataTable
Sets the map of all meta data of the data table.
| Name | Type | Description |
|---|---|---|
meta | Record<string, any> | meta data |
this
▸ setName(name): DataTable
Sets name of the table
| Name | Type | Description |
|---|---|---|
name | string | new table name |
▸ setSilent(bool): DataTable
Set silent mode
| Name | Type | Description |
|---|---|---|
bool | boolean | flag to enable silent mode |
this
▸ setValue(rowIndex, columnIndex, value?): DataTable
Sets the value of the cell at given row and column index.
| Name | Type | Description |
|---|---|---|
rowIndex | number | index of the row. It should be a number greater than or equal to zero, and less than the number of rows as returned by the getNumberOfRows() method. |
columnIndex | number | index of the column. should be a number greater than or equal to zero, and less than the number of columns as returned by the getNumberOfColumns() method. |
Optional value | any | a value to be set to the cell. |
this
▸ sort(column?, comparator?): DataTable
Sorting of DataTable
| Name | Type | Description |
|---|---|---|
Optional column | number | Identifier of Column |
Optional comparator | ComparatorCallback<any> | comparator function that return positive, negative and zero based on condition. |
this
▸ Static getClassName(): string
string