Skip to content

Plugin: DataMap

Description

Utility class that gets and saves data from/to the data source using mapping of columns numbers to object property names.

Members

colToPropCache

Source code

dataMap.colToPropCache : Array

Cached array of properties to columns.

dataSource

Source code

dataMap.dataSource : *

Reference to the original dataset.

DESTINATION_CLIPBOARD_GENERATOR

Source code

DataMap.DESTINATION_CLIPBOARD_GENERATOR : number

DESTINATION_RENDERER

Source code

DataMap.DESTINATION_RENDERER : number

duckSchema

Source code

dataMap.duckSchema : object

Generated schema based on the first row from the source data.

propToColCache

Source code

dataMap.propToColCache : Map

Cached map of properties to columns.

Methods

clear

Source code

dataMap.clear()

Clears the data array.

colToProp

Source code

dataMap.colToProp(column) ⇒ string | number

Returns property name that corresponds with the given column index.

ParamTypeDescription
columnstring
number
Visual column index or another passed argument.

Returns: string | number - Column property, physical column index or passed argument.

countCachedColumns

Source code

dataMap.countCachedColumns() ⇒ number

Count the number of columns cached in the colToProp cache.

Returns: number - Amount of cached columns.

countFirstRowKeys

Source code

dataMap.countFirstRowKeys() ⇒ number

Get the amount of physical columns in the first data row.

Returns: number - Amount of physical columns in the first data row.

createCol

Source code

dataMap.createCol([index], [amount], [options]) ⇒ number

Creates column at the right of the data array.

Emits: Hooks#event:afterCreateCol

ParamTypeDefaultDescription
[index]numberoptional Visual index of the column before which the new column will be inserted.
[amount]number1optional An amount of columns to add.
[options]objectoptional Additional options for created columns.
[options.source]stringoptional Source of method call.
[options.mode]'start'
'end'
optional Sets where the column is inserted: at the start (left in LTR, right in RTL) or at the end (right in LTR, left in LTR) the passed index.

Returns: number - Returns number of created columns.

createDuckSchema

Source code

dataMap.createDuckSchema() ⇒ Array | object

Creates the duck schema based on the current dataset.

createMap

Source code

dataMap.createMap()

Generates cache for property to and from column addressation.

createRow

Source code

dataMap.createRow([index], [amount], [options]) ⇒ number

Creates row at the bottom of the data array.

Emits: Hooks#event:afterCreateRow

ParamTypeDefaultDescription
[index]numberoptional Physical index of the row before which the new row will be inserted.
[amount]number1optional An amount of rows to add.
[options]objectoptional Additional options for created rows.
[options.source]stringoptional Source of method call.
[options.mode]'above'
'below'
optional Sets where the row is inserted: above or below the passed index.

Returns: number - Returns number of created rows.

destroy

Source code

dataMap.destroy()

Destroy instance.

filterData

Source code

dataMap.filterData(index, amount, physicalRows)

Filter unwanted data elements from the data source.

ParamTypeDescription
indexnumberVisual index of the element to remove.
amountnumberNumber of rows to add/remove.
physicalRowsnumberPhysical row indexes.

get

Source code

dataMap.get(row, prop) ⇒ *

Returns single value from the data array.

ParamTypeDescription
rownumberVisual row index.
propnumberThe column property.

getAll

Source code

dataMap.getAll() ⇒ Array

Returns the data array.

getCopyable

Source code

dataMap.getCopyable(row, prop) ⇒ string

Returns single value from the data array (intended for clipboard copy to an external application).

ParamTypeDescription
rownumberVisual row index.
propnumberThe column property.

getCopyableText

Source code

dataMap.getCopyableText([start], [end]) ⇒ string

Return data as copyable text (tab separated columns intended for clipboard copy to an external application).

ParamTypeDescription
[start]objectoptional Start selection position. Visual indexes.
[end]objectoptional End selection position. Visual indexes.

getLength

Source code

dataMap.getLength() ⇒ number

Get data length.

getRange

Source code

dataMap.getRange([start], [end], destination) ⇒ Array

Returns data range as array.

ParamTypeDescription
[start]objectoptional Start selection position. Visual indexes.
[end]objectoptional End selection position. Visual indexes.
destinationnumberDestination of datamap.get.

getSchema

Source code

dataMap.getSchema() ⇒ object

Returns data’s schema.

getText

Source code

dataMap.getText([start], [end]) ⇒ string

Return data as text (tab separated columns).

ParamTypeDescription
[start]objectoptional Start selection position. Visual indexes.
[end]objectoptional End selection position. Visual indexes.

propToCol

Source code

dataMap.propToCol(prop) ⇒ string | number

Translates property into visual column index.

ParamTypeDescription
propstring
number
Column property which may be also a physical column index.

Returns: string | number - Visual column index or passed argument.

recursiveDuckColumns

Source code

dataMap.recursiveDuckColumns(schema, lastCol, parent) ⇒ number

Generates columns’ translation cache.

ParamTypeDescription
schemaobjectAn object to generate schema from.
lastColnumberThe column index.
parentnumberThe property cache for recursive calls.

refreshDuckSchema

Source code

dataMap.refreshDuckSchema()

Refresh the data schema.

removeCol

Source code

dataMap.removeCol([index], [amount], [source]) ⇒ boolean

Removes column from the data array.

Emits: Hooks#event:beforeRemoveCol, Hooks#event:afterRemoveCol

ParamTypeDefaultDescription
[index]numberoptional Visual index of the column to be removed. If not provided, the last column will be removed.
[amount]number1optional Amount of the columns to be removed. If not provided, one column will be removed.
[source]stringoptional Source of method call.

Returns: boolean - Returns false when action was cancelled, otherwise true.

removeRow

Source code

dataMap.removeRow([index], [amount], [source]) ⇒ boolean

Removes row from the data array.

Emits: Hooks#event:beforeRemoveRow, Hooks#event:afterRemoveRow

ParamTypeDefaultDescription
[index]numberoptional Visual index of the row to be removed. If not provided, the last row will be removed.
[amount]number1optional Amount of the rows to be removed. If not provided, one row will be removed.
[source]stringoptional Source of method call.

Returns: boolean - Returns false when action was cancelled, otherwise true.

set

Source code

dataMap.set(row, prop, value)

Saves single value to the data array.

ParamTypeDescription
rownumberVisual row index.
propnumber
string
The column property.
valuestringThe value to set.

spliceCol

Source code

dataMap.spliceCol(col, index, amount, […elements]) ⇒ Array

Add/Removes data from the column.

ParamTypeDescription
colnumberPhysical index of column in which do you want to do splice.
indexnumberIndex at which to start changing the array. If negative, will begin that many elements from the end.
amountnumberAn integer indicating the number of old array elements to remove. If amount is 0, no elements are removed.
[…elements]Arrayoptional The new columns to add.

Returns: Array - Returns removed portion of columns.

spliceData

Source code

dataMap.spliceData(index, deleteCount, elements)

Add/remove row(s) to/from the data source.

ParamTypeDescription
indexnumberPhysical index of the element to add/remove.
deleteCountnumberNumber of rows to remove.
elementsArray<object>Row elements to be added.

spliceRow

Source code

dataMap.spliceRow(row, index, amount, […elements]) ⇒ Array

Add/Removes data from the row.

ParamTypeDescription
rownumberPhysical index of row in which do you want to do splice.
indexnumberIndex at which to start changing the array. If negative, will begin that many elements from the end.
amountnumberAn integer indicating the number of old array elements to remove. If amount is 0, no elements are removed.
[…elements]Arrayoptional The new rows to add.

Returns: Array - Returns removed portion of rows.

visualColumnsToPhysical

Source code

dataMap.visualColumnsToPhysical(index, amount) ⇒ Array

ParamTypeDescription
indexnumberVisual column index.
amountnumberAn amount of rows to translate.

visualRowsToPhysical

Source code

dataMap.visualRowsToPhysical(index, amount) ⇒ number

This ridiculous piece of code maps rows Id that are present in table data to those displayed for user. The trick is, the physical row id (stored in settings.data) is not necessary the same as the visual (displayed) row id (e.g. When sorting is applied).

ParamTypeDescription
indexnumberVisual row index.
amountnumberAn amount of rows to translate.