More Samples
Download Wijmo

CollectionView Adding and Removing Items

The CollectionView provides support for adding items with the methods addNew, commitNew, and cancelNew. Removing items is done with the remove method.

The addNew method adds an empty item to the collection and returns a reference to the new item. The caller can use this return value to initialize the new item. Alternatively, you can provide a CollectionView.newItemCreator function to create and initialize new items.

The addNew method also puts the collection in 'add' mode, suspending sorting and filtering to keep the new item in place until it is committed.

The commitNew method causes the collection to exit 'add mode' and refreshes the collection so sorting and filtering are restored.

The cancelNew method removes the new item from the collection and exits 'add mode'.

You can see how this works by adding items to the grid below.

To add an item, move the selection to the last row, the "New Item Template" (it has an asterisk on the row header). Edit the new item as usual, and when you are done press Enter or move the selection to a different row to commit the new row.

If you press the Escape key while editing the new row, the addition will be canceled and the new row will be removed from the collection.

To remove items, select an entire row by clicking the row header, then press the Delete key. The grid will call the collection's remove method and the item will be removed from the collection.