@model IEnumerable<FlexGridData.Sale>

<h1>
    Validation
</h1>
<p>
    FlexGrid helps with validation in several ways:
</p>
<ol>
    <li>
        <b>Automatic Type Coercion:</b>
        When cell edits are committed, the grid automatically coerces
        values to match the column's data type. It also checks for nulls
        and empty values based on the column's <b>isRequired</b> property.
        If the data is invalid, the original cell value is restored.
    </li>
    <li>
        <b>Data Maps:</b>
        If your grids contain columns that should only allow certain input
        values, add a <b>DataMap</b> to the column to ensure users will not
        be able to type invalid content into the cells.
    </li>
    <li>
        <b>Event-Based Validation:</b>
        The grid raises a <b>cellEditEnding</b> event that allows you
        to check the editor's current value and cancels the edit if the
        new value is invalid.
    </li>
    <li>
        <b>CollectionView-Based Validation:</b>
        The grid honors the collection view's <b>getError</b> method
        to highlight invalid cells and to prevent users from entering
        invalid information.
    </li>
</ol>

<p>
    The grid below demonstrates the first three ways of validation.
    It has a Country column with a data map that prevents users
    from entering invalid countries.
    The <b>cellEditEnding</b> event is used to ensure that the
    'Sales' and 'Expenses' columns contain positive values:
</p>
@(Html.C1().FlexGrid().Id("theGrid").Height(200)
    .AutoGenerateColumns(false)
    .Bind(Model)
    .Columns(cs=>
    {
        cs.Add().Binding("Id").Header("ID").Width("50").IsReadOnly(true);
        cs.Add().Binding("Country").Header("Country").IsRequired(true);
        cs.Add().Binding("Sales").Header("Sales").Format("n2");
        cs.Add().Binding("Expenses").Header("Expenses").Format("n2");
        cs.Add().Binding("Overdue").Header("Overdue");
    })
)