Features

ソート

ソート

このサンプルは、MultiRowコントロールのソート機能を示します。

機能

設定

ソートするフィールド:
ソート順:

説明

このサンプルでは、最初のリストで選択されたフィールド値に基づいてコレクションをソートすることができます。 また、2番目のリストでソート順を指定することもできます。
using MultiRowExplorer.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using C1.Web.Mvc;
using C1.Web.Mvc.Serialization;

namespace MultiRowExplorer.Controllers
{
    public partial class MultiRowController : Controller
    {
        public ActionResult Sorting()
        {
            return View();
        }

        public ActionResult Sorting_Bind([C1JsonRequest] CollectionViewRequest<Sale> requestData)
        {
            return this.C1Json(CollectionViewHelper.Read(requestData, Sale.GetData(500)));
        }
    }
}
@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-multi-row id="sortingMultiRow" class="multirow" is-read-only="true" order-by="ID">
    <c1-items-source read-action-url="@Url.Action("Sorting_Bind")"></c1-items-source>
    <c1-multi-row-cell-group>
        <c1-multi-row-cell binding="ID"></c1-multi-row-cell>
        <c1-multi-row-cell binding="Active"></c1-multi-row-cell>
    </c1-multi-row-cell-group>
    <c1-multi-row-cell-group>
        <c1-multi-row-cell binding="Start" format="MM/dd/yyyy"></c1-multi-row-cell>
        <c1-multi-row-cell binding="End" format="MM/dd/yyyy HH:mm:ss" width="150"></c1-multi-row-cell>
    </c1-multi-row-cell-group>
    <c1-multi-row-cell-group colspan="2">
        <c1-multi-row-cell binding="Country" colspan="2"></c1-multi-row-cell>
        <c1-multi-row-cell binding="Product"></c1-multi-row-cell>
        <c1-multi-row-cell binding="Color"></c1-multi-row-cell>
    </c1-multi-row-cell-group>
    <c1-multi-row-cell-group colspan="2">
        <c1-multi-row-cell binding="Amount"></c1-multi-row-cell>
        <c1-multi-row-cell binding="Amount2"></c1-multi-row-cell>
        <c1-multi-row-cell binding="Discount" colspan="2"></c1-multi-row-cell>
    </c1-multi-row-cell-group>
</c1-multi-row>

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

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

            multiRow = wijmo.Control.getControl("#sortingMultiRow");
            ascending = order === "Ascending";
            sd = multiRow.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(MultiRowRes.Sorting_Text0) <c1-combo-box id="sortingfield" selected-index="0" is-editable="false" selected-index-changed="sortMultiRow"><c1-items-source source-collection="@fields"></c1-items-source></c1-combo-box>
    @Html.Raw(MultiRowRes.Sorting_Text1) <c1-combo-box id="sortingorder" selected-index="0" is-editable="false" selected-index-changed="sortMultiRow"><c1-items-source source-collection="@orders"></c1-items-source></c1-combo-box>
}

@section Summary{
    @Html.Raw(MultiRowRes.Sorting_Text2)
}

@section Description{
    @Html.Raw(MultiRowRes.Sorting_Text3)
}