リモートデータ連結

リモートデータ連結

機能

Settings


エクスポート
エクスポート名:

Description

このサンプルでは、何らかのアクションから取得したデータを含む MVC FlexGrid を Excel ファイルにエクスポートする方法を示します。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using C1.Web.Mvc;
using C1.Web.Mvc.Serializition;
using WebApiExplorer.Models;

namespace WebApiExplorer.Controllers
{
    public partial class MVCFlexGridController : Controller
    {
        private readonly GridExportImportOptions _flexGridRemoteBindModel = new GridExportImportOptions
        {
            NeedExport = true,
            NeedImport = false,
            IncludeColumnHeaders = true
        };

        public ActionResult RemoteBind_Read([C1JsonRequest] CollectionViewRequest<Sale> requestData)
        {
            return this.C1Json(CollectionViewHelper.Read(requestData, Sale.GetData(500)));
        }

        public ActionResult RemoteBind()
        {
            ViewBag.Options = _flexGridRemoteBindModel;
            return View();
        }
    }
}
@using WebApiExplorer.Models
@using C1.Web.Mvc.Grid
@{
    GridExportImportOptions optionsModel = ViewBag.Options;
    ViewBag.DemoSettings = true;
}

@(Html.C1().FlexGrid().Id(optionsModel.ControlId)
    .AutoGenerateColumns(false)
    .AllowSorting(true)
    .IsReadOnly(true)
    .Bind(bl => bl.InitialItemsCount(10).Bind(Url.Action("RemoteBind_Read")))
    .CssClass("grid")
    .SelectionMode(SelectionMode.Row).Filterable()
    .Columns(columns =>
    {
        columns.Add(column => column.Binding("ID"));
        columns.Add(column => column.Binding("Start").Format("MMM d yy"));
        columns.Add(column => column.Binding("End").Format("HH:mm"));
        columns.Add(column => column.Binding("Country"));
        columns.Add(column => column.Binding("Product"));
        columns.Add(column => column.Binding("Color"));
        columns.Add(column => column.Binding("Amount").Format("c"));
        columns.Add(column => column.Binding("Amount2").Format("c"));
        columns.Add(column => column.Binding("Discount").Format("p0"));
        columns.Add(column => column.Binding("Active"));
    })
)

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

@section Description{
    @Html.Raw(Resources.MVCFlexGrid.RemoteBind_Text0)
}