JavaScript Data GridDataMap
- Description
- Members
- Methods
- clear
- colToProp
- countCachedColumns
- countFirstRowKeys
- createCol
- createDuckSchema
- createMap
- createRow
- destroy
- filterData
- get
- getAll
- getCopyable
- getCopyableText
- getLength
- getRange
- getSchema
- getText
- propToCol
- recursiveDuckColumns
- refreshDuckSchema
- removeCol
- removeRow
- set
- spliceCol
- spliceData
- spliceRow
- visualColumnsToPhysical
- visualRowsToPhysical
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 codedataMap.colToPropCache : Array
Cached array of properties to columns.
dataSource
Source codedataMap.dataSource : *
Reference to the original dataset.
DESTINATION_CLIPBOARD_GENERATOR
Source codeDataMap.DESTINATION_CLIPBOARD_GENERATOR : number
DESTINATION_RENDERER
Source codeDataMap.DESTINATION_RENDERER : number
duckSchema
Source codedataMap.duckSchema : object
Generated schema based on the first row from the source data.
propToColCache
Source codedataMap.propToColCache : Map
Cached map of properties to columns.
Methods
clear
Source codedataMap.clear()
Clears the data array.
colToProp
Source codedataMap.colToProp(column) ⇒ string | number
Returns property name that corresponds with the given column index.
Param | Type | Description |
---|---|---|
column | string number | Visual column index or another passed argument. |
Returns: string
| number
- Column property, physical column index or passed argument.
countCachedColumns
Source codedataMap.countCachedColumns() ⇒ number
Count the number of columns cached in the colToProp
cache.
Returns: number
- Amount of cached columns.
countFirstRowKeys
Source codedataMap.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 codedataMap.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. |
Returns: number
- Returns number of created columns.
createDuckSchema
Source codedataMap.createDuckSchema() ⇒ Array | object
Creates the duck schema based on the current dataset.
createMap
Source codedataMap.createMap()
Generates cache for property to and from column addressation.
createRow
Source codedataMap.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. |
Returns: number
- Returns number of created rows.
destroy
Source codedataMap.destroy()
Destroy instance.
filterData
Source codedataMap.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
Source codedataMap.get(row, prop) ⇒ *
Returns single value from the data array.
Param | Type | Description |
---|---|---|
row | number | Visual row index. |
prop | number | The column property. |
getAll
Source codedataMap.getAll() ⇒ Array
Returns the data array.
getCopyable
Source codedataMap.getCopyable(row, prop) ⇒ string
Returns single value from the data array (intended for clipboard copy to an external application).
Param | Type | Description |
---|---|---|
row | number | Physical row index. |
prop | number | The column property. |
getCopyableText
Source codedataMap.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
Source codedataMap.getLength() ⇒ number
Get data length.
getRange
Source codedataMap.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
Source codedataMap.getSchema() ⇒ object
Returns data's schema.
getText
Source codedataMap.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. |
propToCol
Source codedataMap.propToCol(prop) ⇒ string | number
Translates property into visual column index.
Param | Type | Description |
---|---|---|
prop | string number | Column property which may be also a physical column index. |
Returns: string
| number
- Visual column index or passed argument.
recursiveDuckColumns
Source codedataMap.recursiveDuckColumns(schema, lastCol, parent) ⇒ number
Generates columns' translation cache.
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
Source codedataMap.refreshDuckSchema()
Refresh the data schema.
removeCol
Source codedataMap.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 cancelled, otherwise true
.
removeRow
Source codedataMap.removeRow([index], [amount], [source]) ⇒ 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. |
Returns: boolean
- Returns false
when action was cancelled, otherwise true
.
set
Source codedataMap.set(row, prop, value)
Saves single value to the data array.
Param | Type | Description |
---|---|---|
row | number | Visual row index. |
prop | number | The column property. |
value | string | The value to set. |
spliceCol
Source codedataMap.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
Source codedataMap.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
Source codedataMap.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
Source codedataMap.visualColumnsToPhysical(index, amount) ⇒ Array
Param | Type | Description |
---|---|---|
index | number | Visual column index. |
amount | number | An amount of rows to translate. |
visualRowsToPhysical
Source codedataMap.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. |