Skip to main content

add()

adds a new item to the component

note

Please note that data should be loaded into DataCollection via the parse() method. The add() method is primarily intended for loading standalone elements or small groups of elements, so its loads data slower than the parse() method.

Usage​

type Id = string | number; 
add(newItem: IDataItem | IDataItem[], index?: number): Id | Id[];

Parameters:

  • newItem: IDataItem | IDataItem[] - the object of a new item or an array of item objects
  • index?: number - optional, the index of the position starting from which new items will be added

Returns:

Either item's id or an array with ids of items.

Example

// adding a new item into the beginning of a data collection 
component.data.add({ "value": 57.44787660011765, "id": "u1565340894584" }, 0);

// adding an array of new items into a data collection
component.data.add([
{
"value": 57.44787660011765,
"id": "u1565340894584"
},
{
"value": 14.612810637958095,
"id": "u1565340894585"
},
{
"value": 83.9707181117741,
"id": "u1565340894586"
},
{
"value": 59.01285878162044,
"id": "u1565340894587"
}
]);

When data is grouped, DataCollection recalculates the counters and aggregated values of the groups over the resulting data.

Related article: Controls and operations

Related sample: Data. Add

Change log:

The possibility to pass an array of items is added in v6.1.