ComponentOne
Web API Explorer ASP.NET Web API Explorer

Disable Server Reading

Disable Server Reading

Features

Settings


Export
Export Name :

Description

This sample shows how to export mvc flexgrid to excel with the DisableServerRead property. When it is set to True, all the items will be transferred to the client side. So it just exports the current flexgrid with all the data in client. Otherwise, will obtain the data from server side first, then export the flexgrid with all data to excel file.
using System.Collections.Generic;
using C1.Web.Mvc;
using C1.Web.Mvc.Serialization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApiExplorer.Models;

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

        private readonly ControlOptions _disableServerReadSetting = new ControlOptions
        {
            Options = new OptionDictionary
            {
                {"Disable Server Read",new OptionItem{Values = new List<string> {"True", "False"},CurrentValue = "True"}}
            }
        };

        public IActionResult DisableServerRead(IFormCollection collection)
        {
            _disableServerReadSetting.LoadPostData(collection);
            ViewBag.DemoOptions = _disableServerReadSetting;
            ViewBag.Options = _flexGridDisableServerReadModel;
            return View();
        }

        public ActionResult DisableServerRead_Bind([C1JsonRequest] CollectionViewRequest<Sale> requestData)
        {
            return this.C1Json(CollectionViewHelper.Read(requestData, Sale.GetData(500)));
        }
    }
}
@{
    ControlOptions optionsModel = ViewBag.DemoOptions;
    GridExportImportOptions exportOptionsModel = ViewBag.Options;
    ViewBag.DemoSettings = true;
}

<c1-flex-grid id="@exportOptionsModel.ControlId" auto-generate-columns="true" class="grid" is-read-only="true">
    <c1-flex-grid-filter></c1-flex-grid-filter>
    <c1-items-source disable-server-read="@(Convert.ToBoolean(optionsModel.Options["Disable Server Read"].CurrentValue))"
                     initial-items-count="10"
                     read-action-url="@Url.Action("DisableServerRead_Bind")"></c1-items-source>
</c1-flex-grid>

@section Settings{
    <p>@await Html.PartialAsync("_OptionsMenu", optionsModel)</p>
    <p>@await Html.PartialAsync("_FlexGridOptions", exportOptionsModel)</p>
}

@section Description{
    @Html.Raw(MVCFlexGrid.DisableServerRead_Text0)
}