@model IEnumerable<Sale>

@{
    var fields = new[] { "ID", "Start", "End", "Country", "Product", "Color", "Amount", "Amount2", "Discount", "Active" };
    var orders = new[] { "Ascending", "Descending" };
    ViewBag.DemoSettings = true;
    ViewBag.SettingsByMenu = false;
}

<c1-flex-grid id="flexgrid" class="grid" auto-generate-columns="false" is-read-only="true" order-by="ID">
    <c1-flex-grid-column binding="ID"></c1-flex-grid-column>
    <c1-flex-grid-column binding="Start"></c1-flex-grid-column>
    <c1-flex-grid-column binding="End"></c1-flex-grid-column>
    <c1-flex-grid-column binding="Country"></c1-flex-grid-column>
    <c1-flex-grid-column binding="Product"></c1-flex-grid-column>
    <c1-flex-grid-column binding="Color"></c1-flex-grid-column>
    <c1-flex-grid-column binding="Amount" format="c"></c1-flex-grid-column>
    <c1-flex-grid-column binding="Amount2" format="c"></c1-flex-grid-column>
    <c1-flex-grid-column binding="Discount" format="p0"></c1-flex-grid-column>
    <c1-flex-grid-column binding="Active"></c1-flex-grid-column>
    <c1-items-source read-action-url="@Url.Action("Sorting_Bind")"></c1-items-source>
</c1-flex-grid>

@section Scripts{
<script>
    var field = "ID", order = "Ascending";
    function sortGrid(combo) {
        var flexGrid, ascending, sd;
        if (combo.hostElement.id === "sortingfield")
            field = combo.selectedValue;
        if (combo.hostElement.id === "sortingorder")
            order = combo.selectedValue;

        if (!field || !order) {
            return;
        }

        flexGrid = wijmo.Control.getControl("#flexgrid");
        ascending = order === "Ascending";
        sd = flexGrid.collectionView.sortDescriptions;
        sdNew = new wijmo.collections.SortDescription(field, ascending);

        // remove any old sort descriptors and add the new one
        sd.splice(0, sd.length, sdNew);
    }
</script>
}

@section Settings {
    @Html.Raw(FlexGridRes.Sorting_SortingField) : <c1-combo-box id="sortingfield" selected-index="0" is-editable="false" selected-index-changed="sortGrid"><c1-items-source source-collection="@fields"></c1-items-source></c1-combo-box>
    @Html.Raw(FlexGridRes.Sorting_SortingOrder) : <c1-combo-box id="sortingorder" selected-index="0" is-editable="false" selected-index-changed="sortGrid"><c1-items-source source-collection="@orders"></c1-items-source></c1-combo-box>
}

@section Description{
    @Html.Raw(FlexGridRes.Sorting_Text0)
}