DataMap
Description
Utility class that gets and saves data from/to the data source using mapping of columns numbers to object property names.
Members
DESTINATION_CLIPBOARD_GENERATOR
DataMap.DESTINATION_CLIPBOARD_GENERATOR : number
DESTINATION_RENDERER
DataMap.DESTINATION_RENDERER : number
Methods
clear
dataMap.clear()
Clears the data array.
countCachedColumns
dataMap.countCachedColumns() ⇒ number
Count the number of columns cached in the colToProp cache.
Returns: number - Amount of cached columns.
countFirstRowKeys
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
dataMap.createCol([index], [amount], [options]) ⇒ number
Creates column at the right of the data array.
Emits: Hooks#event:afterCreateCol
| Param | Type | Default | Description |
|---|---|---|---|
| [index] | number | optional Visual index of the column before which the new column will be inserted. | |
| [amount] | number | 1 | optional An amount of columns to add. |
| [options] | object | optional Additional options for created columns. | |
| [options.source] | string | optional 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. | |
| [options.fillsMinimumSize] | boolean | optional Whether the columns are appended to satisfy minCols/minSpareCols. Only such columns are given back when one of those options is lowered. |
Returns: number - Returns number of created columns.
createDuckSchema
dataMap.createDuckSchema() ⇒ Array | object
Creates the duck schema based on the current dataset.
createMap
dataMap.createMap()
Generates cache for property to and from column addressation.
createRow
dataMap.createRow([index], [amount], [options]) ⇒ number
Creates row at the bottom of the data array.
Emits: Hooks#event:afterCreateRow
| Param | Type | Default | Description |
|---|---|---|---|
| [index] | number | optional Physical index of the row before which the new row will be inserted. | |
| [amount] | number | 1 | optional An amount of rows to add. |
| [options] | object | optional Additional options for created rows. | |
| [options.source] | string | optional Source of method call. | |
| [options.mode] | 'above' 'below' | optional Sets where the row is inserted: above or below the passed index. | |
| [options.fillsMinimumSize] | boolean | optional Whether the rows are appended to satisfy minRows/minSpareRows. Only such rows are given back when one of those options is lowered. |
Returns: number - Returns number of created rows.
destroy
dataMap.destroy()
Destroy instance.
filterData
dataMap.filterData(index, amount, physicalRows)
Filter unwanted data elements from the data source.
| Param | Type | Description |
|---|---|---|
| index | number | Visual index of the element to remove. |
| amount | number | Number of rows to add/remove. |
| physicalRows | number | Physical row indexes. |
get
dataMap.get(row, prop, [options]) ⇒ *
Returns single value from the data array.
| Param | Type | Default | Description |
|---|---|---|---|
| row | number | Visual row index. | |
| prop | number string function null | The column property, a columns[].data accessor function, or null when the caller’s column index named no column (see colToProp()). | |
| [options] | object | optional Read options. | |
| [options.skipValueGetter] | boolean | false | optional When true, returns the stored value without the column’s valueGetter (the modifyRowData and modifyData hooks still apply). Bulk validation reads cells this way, because an edit validates the stored value too. |
getAll
dataMap.getAll() ⇒ Array
Returns the data array.
getCopyable
dataMap.getCopyable(row, prop) ⇒ *
Returns single value from the data array (intended for clipboard copy to an external application).
The value is returned as it is stored, so it can be of any type. Core#getCopyableData()
converts it to a string; the clipboard and Autofill consume it raw.
| Param | Type | Description |
|---|---|---|
| row | number | Visual row index. |
| prop | number string function | The column property, or a columns[].data accessor function. |
getCopyableText
dataMap.getCopyableText([start], [end]) ⇒ string
Return data as copyable text (tab separated columns intended for clipboard copy to an external application).
| Param | Type | Description |
|---|---|---|
| [start] | object | optional Start selection position. Visual indexes. |
| [end] | object | optional End selection position. Visual indexes. |
getLength
dataMap.getLength() ⇒ number
Get data length.
getRange
dataMap.getRange([start], [end], destination) ⇒ Array
Returns data range as array.
| Param | Type | Description |
|---|---|---|
| [start] | object | optional Start selection position. Visual indexes. |
| [end] | object | optional End selection position. Visual indexes. |
| destination | number | Destination of datamap.get. |
getSchema
dataMap.getSchema() ⇒ object
Returns data’s schema.
getText
dataMap.getText([start], [end]) ⇒ string
Return data as text (tab separated columns).
| Param | Type | Description |
|---|---|---|
| [start] | object | optional Start selection position. Visual indexes. |
| [end] | object | optional End selection position. Visual indexes. |
isTrailingFillerColumn
dataMap.isTrailingFillerColumn(physicalColumn) ⇒ boolean
Checks whether a column is one of the filler columns at the end of the data set, that is, one minCols or
minSpareCols appended with no other column after it.
| Param | Type | Description |
|---|---|---|
| physicalColumn | number null | The physical column index. |
isTrailingFillerRow
dataMap.isTrailingFillerRow(physicalRow) ⇒ boolean
Checks whether a row is one of the filler rows at the end of the data set, that is, one minRows or
minSpareRows appended with no other row after it.
| Param | Type | Description |
|---|---|---|
| physicalRow | number null | The physical row index. |
propToCol
dataMap.propToCol(prop) ⇒ string | number | function | null
Translates property into visual column index.
| Param | Type | Description |
|---|---|---|
| prop | string number function null | Column property, a physical column index, a columns[].data accessor function, or null. |
Returns: string | number | function | null - Visual column index, null when the argument names no
visible column, or the passed argument when it is a property this data set does not use.
recursiveDuckColumns
dataMap.recursiveDuckColumns(schema, lastCol, parent) ⇒ number
Generates columns’ translation cache. A plain object is walked, and every primitive leaf
(null, undefined, a number, a string, a boolean) gets a column, whatever its default
value. An array, a function, any other object (a Date, a Map) and the __children key get
none. deepObjectSize() still counts an array, a function and such an object as a column, so
the count can exceed the number of properties registered here.
| Param | Type | Description |
|---|---|---|
| schema | object | An object to generate schema from. |
| lastCol | number | The column index. |
| parent | number | The property cache for recursive calls. |
refreshDuckSchema
dataMap.refreshDuckSchema()
Refresh the data schema.
removeCol
dataMap.removeCol([index], [amount], [source]) ⇒ boolean
Removes column from the data array.
Emits: Hooks#event:beforeRemoveCol, Hooks#event:afterRemoveCol
| Param | Type | Default | Description |
|---|---|---|---|
| [index] | number | optional Visual index of the column to be removed. If not provided, the last column will be removed. | |
| [amount] | number | 1 | optional Amount of the columns to be removed. If not provided, one column will be removed. |
| [source] | string | optional Source of method call. |
Returns: boolean - Returns false when action was canceled, otherwise true.
removeRow
dataMap.removeRow([index], [amount], [source], [onRowsRemoved]) ⇒ boolean
Removes row from the data array.
Emits: Hooks#event:beforeRemoveRow, Hooks#event:afterRemoveRow
| Param | Type | Default | Description |
|---|---|---|---|
| [index] | number | optional Visual index of the row to be removed. If not provided, the last row will be removed. | |
| [amount] | number | 1 | optional Amount of the rows to be removed. If not provided, one row will be removed. |
| [source] | string | optional Source of method call. | |
| [onRowsRemoved] | function | optional Called with the physical rows really removed (the list after beforeRemoveRow widened it), before afterRemoveRow runs. Core#alter() uses it to follow the rows of the groups it removes next. |
Returns: boolean - Returns false when action was canceled, otherwise true.
set
dataMap.set(row, prop, value)
Saves single value to the data array.
| Param | Type | Description |
|---|---|---|
| row | number | Visual row index. |
| prop | number string function null | The column property, a columns[].data accessor function, or null when the caller’s column index named no column (see colToProp()). |
| value | string | The value to set. |
setAtPhysicalRow
dataMap.setAtPhysicalRow(physicalRow, prop, value, row)
Saves single value to the data array, at a physical row. A change that waited for its validator is written this way, to the record it was made on, which a trimming map may have taken out of the visual space meanwhile.
| Param | Type | Description |
|---|---|---|
| physicalRow | number | Physical row index. |
| prop | number string function null | The column property, a columns[].data accessor function, or null when the caller’s column index named no column (see colToProp()). |
| value | string | The value to set. |
| row | number null | The visual row index the modifyData hook receives (null for a row the visual space does not hold). |
spliceCol
dataMap.spliceCol(col, index, amount, […elements]) ⇒ Array
Add/Removes data from the column.
| Param | Type | Description |
|---|---|---|
| col | number | Physical index of column in which do you want to do splice. |
| index | number | Index at which to start changing the array. If negative, will begin that many elements from the end. |
| amount | number | An integer indicating the number of old array elements to remove. If amount is 0, no elements are removed. |
| […elements] | Array | optional The new columns to add. |
Returns: Array - Returns removed portion of columns.
spliceData
dataMap.spliceData(index, deleteCount, elements)
Add/remove row(s) to/from the data source.
| Param | Type | Description |
|---|---|---|
| index | number | Physical index of the element to add/remove. |
| deleteCount | number | Number of rows to remove. |
| elements | Array<object> | Row elements to be added. |
spliceRow
dataMap.spliceRow(row, index, amount, […elements]) ⇒ Array
Add/Removes data from the row.
| Param | Type | Description |
|---|---|---|
| row | number | Physical index of row in which do you want to do splice. |
| index | number | Index at which to start changing the array. If negative, will begin that many elements from the end. |
| amount | number | An integer indicating the number of old array elements to remove. If amount is 0, no elements are removed. |
| […elements] | Array | optional The new rows to add. |
Returns: Array - Returns removed portion of rows.
visualColumnsToPhysical
dataMap.visualColumnsToPhysical(index, amount) ⇒ Array
| Param | Type | Description |
|---|---|---|
| index | number | Visual column index. |
| amount | number | An amount of rows to translate. |
visualRowsToPhysical
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).
| Param | Type | Description |
|---|---|---|
| index | number | Visual row index. |
| amount | number | An amount of rows to translate. |