CollectionView
CollectionView
ソート
機能
サンプル
設定
説明
CollectionView でソートがどのように操作するかを示しています。
ソース
SortingController.cs
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using C1.Web.Mvc; using C1.Web.Mvc.Serialization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using MvcExplorer.Models; namespace MvcExplorer.Controllers { public partial class CollectionViewController : Controller { private readonly ControlOptions _cVSorting = new ControlOptions { Options = new OptionDictionary { {"Sort Nulls", new OptionItem {Values = new List<string> { "Natural", "First", "Last" }, CurrentValue = "Natural"}} } }; public ActionResult Sorting(IFormCollection collection) { _cVSorting.LoadPostData(collection); ViewBag.DemoOptions = _cVSorting; return View(); } public ActionResult Sorting_Bind([C1JsonRequest] CollectionViewRequest<Sale> requestData) { var extraData = requestData.ExtraRequestData .ToDictionary(kvp => kvp.Key, kvp => new StringValues(kvp.Value.ToString())); var data = new FormCollection(extraData); _optionsModel.LoadPostData(data); var model = Sale.GetData(10).ToList(); var nullObj = new Sale { }; model.Add(nullObj); return this.C1Json(CollectionViewHelper.Read(requestData, model)); } } }
Sorting.cshtml
@using C1.Web.Mvc.Grid @model IEnumerable<Sale> @{ ControlOptions optionsModel = ViewBag.DemoOptions; ViewBag.DemoSettings = true; } <c1-items-source id="CVService" read-action-url="@Url.Action("Sorting_Bind")" sort-nulls="@((CollectionViewSortNulls)Enum.Parse(typeof(CollectionViewSortNulls), optionsModel.Options["Sort Nulls"].CurrentValue))"> </c1-items-source> <c1-flex-grid id="FlexGridCV" items-source-id="CVService" auto-generate-columns="false" class="grid"> <c1-flex-grid-column binding="ID"></c1-flex-grid-column> <c1-flex-grid-column binding="Start" format="MMM d yy"></c1-flex-grid-column> <c1-flex-grid-column binding="End" format="HH:mm"></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="Active"></c1-flex-grid-column> </c1-flex-grid> @section Settings{ @await Html.PartialAsync("_OptionsMenu", optionsModel) } @section Description{ <p>@Html.Raw(CollectionViewRes.Sorting_Text0)</p> }
マニュアル