ComponentOne
Web API Explorer ASP.NET Web API Explorer

MVCFlexGrid

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 export 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;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApiExplorer.Models;
using C1.Web.Mvc;

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 ActionResult DisableServerRead(FormCollection collection)
        {
            IValueProvider data = collection;
            if (CallbackManager.CurrentIsCallback)
            {
                var request = CallbackManager.GetCurrentCallbackData<CollectionViewRequest<object>>();
                if (request != null && request.ExtraRequestData != null)
                {
                    var extraData = request.ExtraRequestData.Cast<DictionaryEntry>()
                        .ToDictionary(kvp => (string)kvp.Key, kvp => kvp.Value.ToString());
                    data = new DictionaryValueProvider<string>(extraData, CultureInfo.CurrentCulture);
                }
            }

            _disableServerReadSetting.LoadPostData(data);
            ViewBag.DemoOptions = _disableServerReadSetting;
            ViewBag.Options = _flexGridDisableServerReadModel;
            return View(Sale.GetData(500));
        }
    }
}
@using WebApiExplorer.Models
@model IEnumerable<Sale>

@{
    ControlOptions optionsModel = ViewBag.DemoOptions;
    GridExportImportOptions exportOptionsModel = ViewBag.Options;
    ViewBag.DemoSettings = true;
}

@(Html.C1().FlexGrid<Sale>()
    .AutoGenerateColumns(true)
    .Id(exportOptionsModel.ControlId)
    .CssClass("grid")
    .IsReadOnly(true)
    .Bind(b => b.DisableServerRead(Convert.ToBoolean(optionsModel.Options["Disable Server Read"].CurrentValue)).InitialItemsCount(10).Bind(Model))
)

@section Settings{
    @Html.Partial("_OptionsMenu", optionsModel)
    <br/>
    @Html.Partial("_FlexGridOptions", exportOptionsModel)
}

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