Features

フィルタリング

フィルタリング

このサンプルは、MultiRowコントロールでフィルタ処理を使用する方法を示します。

機能

設定

using C1.Web.Mvc;
using MultiRowExplorer.Models;
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Linq;

namespace MultiRowExplorer.Controllers
{
    public partial class MultiRowController : Controller
    {
        private static OptionItem CreateOptionItem()
        {
            return new OptionItem { Values = new List<string> { "None", "Condition", "Value", "Both" }, CurrentValue = "Both" };
        }

        private readonly ControlOptions _filterOptions = new ControlOptions
        {
            Options = new OptionDictionary
            {
                {"CustomerState", CreateOptionItem()},
                {"CustomerCity", CreateOptionItem()},
                {"ShipperName", CreateOptionItem()},
                {"ShipperExpress", CreateOptionItem()},
                {"Amount", CreateOptionItem()}
            }
        };

        public ActionResult Filter(FormCollection data)
        {
            _filterOptions.LoadPostData(data);
            ViewBag.DemoOptions = _filterOptions;
            ViewBag.FilterTypes = GetFilterTypes(_filterOptions);
            return View(Orders.GetOrders());
        }

        private Dictionary<string, FilterType> GetFilterTypes(ControlOptions controlOptions)
        {
            var filterTypes = new Dictionary<string, FilterType>();
            foreach (var item in controlOptions.Options)
            {
                filterTypes.Add(item.Key, (FilterType)Enum.Parse(typeof(FilterType), item.Value.CurrentValue));
            }
            return filterTypes;
        }
    }
}
@model IEnumerable<Orders.Order>
@{
    ControlOptions optionsModel = ViewBag.DemoOptions;
    Dictionary<string, FilterType> filterTypes = ViewBag.FilterTypes;
    ViewBag.DemoSettings = true;
    ViewBag.DemoDescription = false;
}

@(Html.C1().MultiRow<Orders.Order>()
        .Id("filteringMultiRow")
        .Bind(Model)
        .PageSize(25)
        .IsReadOnly(true)
        .LayoutDefinition(LayoutDefinitionsBuilders.ThreeLines)
        .SelectionMode(SelectionMode.Row)
        .SortingType(AllowSorting.SingleColumn)
        .Filterable(f => f.DefaultFilterType(FilterType.Both)
            .ColumnFilters(cfsb =>
            {
                foreach (var item in filterTypes)
                {
                    cfsb.Add(cfb => cfb.Column(item.Key).FilterType(item.Value));
                }
            })
        )
        .CssClass("multirow")
)

@(Html.C1().Pager().Owner("filteringMultiRow"))

@section Settings{
    @Html.Partial("_OptionsMenu", optionsModel)
}

@section Summary{
    @Html.Raw(Resources.MultiRowExplorer.Filter_Text0)
}