Last updated

API / geotoolkit / data / DataTable / DataTable

Class: DataTable

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'}
]
});

Hierarchy

Table of contents

Constructors
Methods

Contents

Constructors

new DataTable(data)

new DataTable(data?)

Parameters

Name Type
Optional dataOptions

Overrides

AbstractDataTable.constructor

Methods

addColumn

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'
});

Parameters

Name Type Description
columnColumna DataSeries object or a object containing descriptions.

Returns

DataTable

this


addRow

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]);

Parameters

Name Type Description
cellArrayany[]array of cells
Optional ignoreMissingValuebooleanignore missing value

Returns

DataTable

this


addRows

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]]);

Parameters

Name Type Description
rowsArraynumber | any[]rows data or a number of empty rows to add
Optional ignoreMissingValuebooleanignore missing value

Returns

DataTable

this


clear

clear(): DataTable

Clears all cells of the data table.

Returns

DataTable

this


clone

clone(copyData?): DataTable

Returns a clone of the data table.

Parameters

Name Type Description
Optional copyDatabooleancopy data

Returns

DataTable

clone


dispose

dispose(): void

Dispose.

Returns

void

Inherited from

AbstractDataTable.dispose


fillTable

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]]);

Parameters

Name Type Description
columnsArrayany[]array of values by column

Returns

DataTable

this


getClassName

getClassName(): string

Returns

string

Inherited from

AbstractDataTable.getClassName


getColumn

getColumn(columnIndex): DataSeries<any>

Returns column by index

Parameters

Name Type Description
columnIndexnumberindex of column

Returns

DataSeries<any>

DataSeries

Overrides

AbstractDataTable.getColumn


getColumnById

getColumnById(id): DataSeries<any>

Returns column by specified identifier. If multiple columns have the same identifier, the first one will be returned.

Parameters

Name Type Description
idstring | numberidentifier of the column

Returns

DataSeries<any>

a column

Overrides

AbstractDataTable.getColumnById


getColumnByName

getColumnByName(name): DataSeries<any>

Returns column by specified name. If multiple columns have the same name, the first one will be returned.

Parameters

Name Type Description
namestringname of the column

Returns

DataSeries<any>

a column

Overrides

AbstractDataTable.getColumnByName


getColumnProperties

getColumnProperties(columnIndex): Record<string, any>

Returns the map of all properties of specified column.

Parameters

Name Type Description
columnIndexnumberindex of the column

Returns

Record<string, any>

Inherited from

AbstractDataTable.getColumnProperties


getMetaData

getMetaData(): Record<string, any>

Returns the map of all meta data of the data table. This method returns the reference to the meta data.

Returns

Record<string, any>

Overrides

AbstractDataTable.getMetaData


getName

getName(): string

Returns table name

Returns

string

Inherited from

AbstractDataTable.getName


getNumberOfColumns

getNumberOfColumns(): number

Returns the number of columns in the data table.

Returns

number

number of columns

Overrides

AbstractDataTable.getNumberOfColumns


getNumberOfRows

getNumberOfRows(): number

Returns number of rows.

Returns

number

Overrides

AbstractDataTable.getNumberOfRows


getRow

getRow(rowIndex, cells?): any[]

Returns an array of values at specified row index.

Parameters

Name Type Description
rowIndexnumberindex 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 cellsany[]optional array to fill values

Returns

any[]

array of values


getValue

getValue(rowIndex, columnIndex): any

Return the value of a cell.

Parameters

Name Type Description
rowIndexnumberindex 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.
columnIndexnumberindex 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.

Returns

any

Overrides

AbstractDataTable.getValue


hasEventListener

hasEventListener(type, callback?): boolean

Check if a list of event listeners for this type contains this listener

Parameters

Name Type Description
typestringtype of event or property
Optional callbackFunctionto be called, if null, check if any callback is registered

Returns

boolean

Inherited from

AbstractDataTable.hasEventListener


indexOfColumn

indexOfColumn(column): number

Returns the index of specified column.

Parameters

Name Type Description
columnDataSeries<any>column

Returns

number

index

Overrides

AbstractDataTable.indexOfColumn


insertColumn

insertColumn(columnIndex, column): DataTable

Inserts a column at specified index.

Parameters

Name Type Description
columnIndexnumbercolumn index to insert
columnColumncolumn

Returns

DataTable

this


insertRow

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]);

Parameters

Name Type Description
rowIndexnumberindex number where to insert the new row
cellArrayany[]array of cells

Returns

DataTable

this


isDisposed

isDisposed(): boolean

Returns whether this object has been disposed

Returns

boolean

Inherited from

AbstractDataTable.isDisposed


isSilent

isSilent(): boolean

Return true if the event dispatcher doesn't notify any events

Returns

boolean

Inherited from

AbstractDataTable.isSilent


notify

notify<E>(type, source, args?): DataTable

Notify listeners

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEevent types
sourceDataTableof the event
Optional argsEventMap[E]arguments of the event

Returns

DataTable

this

Overrides

AbstractDataTable.notify


off

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.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
Optional typeEtype of the event
Optional callback(eventType: E, sender: DataTable, args: EventMap[E]) => voidfunction to be called

Returns

DataTable

this

Overrides

AbstractDataTable.off


on

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.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEtype of event or property
callback(eventType: E, sender: DataTable, args: EventMap[E]) => voidto be called

Returns

DataTable

this

Overrides

AbstractDataTable.on


query

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;
});

Returns

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

removeColumns(columnIndex, numberOfColumns?): DataTable

Removes column(s) at the specified index.

Parameters

Name Type Description
columnIndexnumbercolumn index to remove
Optional numberOfColumnsnumbernumber of columns to remove

Returns

DataTable

this


removeRows

removeRows(rowIndex, numberOfRows?): DataTable

Removes row(s) from all columns in the data table.

Parameters

Name Type Description
rowIndexnumberthe index number where to start removing the rows
Optional numberOfRowsnumberthe amount of rows to remove

Returns

DataTable

this


setColumnProperties

setColumnProperties(columnIndex, properties): DataTable

Sets properties of specified column.

Parameters

Name Type Description
columnIndexnumberindex of the column
propertiesRecord<string, any>a map of properties for the specified column. All properties will be merged with existing ones.

Returns

DataTable

this


setColumnValues

setColumnValues(columnIndex, cellArray): DataTable

Sets an array of values at specified column index.

Parameters

Name Type Description
columnIndexnumberindex of the column
cellArrayany[]array of values to set

Returns

DataTable

this


setMetaData

setMetaData(meta): DataTable

Sets the map of all meta data of the data table.

Parameters

Name Type Description
metaRecord<string, any>meta data

Returns

DataTable

this


setName

setName(name): DataTable

Sets name of the table

Parameters

Name Type Description
namestringnew table name

Returns

DataTable

Inherited from

AbstractDataTable.setName


setSilent

setSilent(bool): DataTable

Set silent mode

Parameters

Name Type Description
boolbooleanflag to enable silent mode

Returns

DataTable

this

Inherited from

AbstractDataTable.setSilent


setValue

setValue(rowIndex, columnIndex, value?): DataTable

Sets the value of the cell at given row and column index.

Parameters

Name Type Description
rowIndexnumberindex 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.
columnIndexnumberindex 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 valueanya value to be set to the cell.

Returns

DataTable

this


sort

sort(column?, comparator?): DataTable

Sorting of DataTable

Parameters

Name Type Description
Optional columnnumberIdentifier of Column
Optional comparatorComparatorCallback<any>comparator function that return positive, negative and zero based on condition.

Returns

DataTable

this


getClassName

Static getClassName(): string

Returns

string

Inherited from

AbstractDataTable.getClassName