@model IEnumerable<FlexGridData.Sale>

<h1>
    CollectionView Adding and Removing Items
</h1>
<p>
    The <b>CollectionView</b> provides support for adding
    items with the methods <b>addNew</b>, <b>commitNew</b>,
    and <b>cancelNew</b>. Items are removed using the
    <b>remove</b> method.
</p>
<p>
    The <b>addNew</b> 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
    <b>CollectionView.newItemCreator</b> function to
    create and initialize the new items.
</p>
<p>
    The <b>addNew</b> method also puts the collection in
    'add' mode, suspending sorting and filtering to keep
    the new item in place until it is committed.
</p>
<p>
    The <b>commitNew</b> method causes the collection
    to exit 'add mode', refreshes the collection and 
    restores sorting and filtering.
</p>
<p>
    The <b>cancelNew</b> method removes the new item from
    the collection and exits 'add mode'.
</p>
<p>
    Add items in the grid below to observe how this works.
</p>
<p>
    To add an item, move the selection to the last
    row, the "New Item Template" (having an asterisk on
    the row header). Edit the new item as usual, and
    press Enter or move the selection to a different row
    to commit the new row.
</p>
<p>
    To cancel the addition, press the Escape key while editing
    the new row. The row will be removed from the collection.
</p>
<p>
    To remove items, select an entire row by clicking
    the row header, and then press the Delete key. The grid
    will call the collection's <b>remove</b> method
    and the item will be removed from the collection.
</p>

@(Html.C1().FlexGrid().Id("theGrid")
    .Bind(b=>b.Bind(Model).DisableServerRead(true))
    .AutoGenerateColumns(false)
    .Columns(cs=>
    {
        cs.Add().Binding("Country").Header("Country");
        cs.Add().Binding("Downloads").Header("Downloads");
        cs.Add().Binding("Sales").Header("Sales");
        cs.Add().Binding("Expenses").Header("Expenses");
    })
)