Skip to main content

beforeAdd

fires before adding a new item/items into a data collection

beforeAdd: (newItem: IDataItem, batch: IDataItem[], index: number) => boolean | void;

Parameters:

  • newItem: object - the object of an added item
  • batch: array - an array of added items
  • index: number - the index of the added item within the batch

Returns:

Return false to prevent an item adding into a data collection; otherwise, true.

Example

component.data.events.on("beforeAdd", function(newItem, batch, index){
console.log("New items will be added");
return true;
});