FlexGrid
Preserve White Space
The sampe shows how to make the grid keep whitespace in cells as they appear in the data or whether it should collapse the whitespace into a single space character.
Features
Sample
Settings
Description
The sampe shows how to make the grid keep whitespace in cells as they appear in the data or whether it should collapse the whitespace into a single space character.
When 'Preserve White Space' value is set True, the grid will keep whitespace in cells. See Color column for more clartity.
Source
PreserveWhiteSpaceController.cs
using MvcExplorer.Models; using System.Collections.Generic; using System.Web.Mvc; using System.Linq; namespace MvcExplorer.Controllers { public partial class FlexGridController : Controller { private readonly ControlOptions _preserveWhiteSpaceDataModel = new ControlOptions { Options = new OptionDictionary { {"Preserve White Space", new OptionItem {Values = new List<string> { "True", "False"}, CurrentValue = "True"}} } }; public ActionResult PreserveWhiteSpace(FormCollection collection) { IValueProvider data = collection; _preserveWhiteSpaceDataModel.LoadPostData(data); ViewBag.DemoOptions = _preserveWhiteSpaceDataModel; var model = Sale.GetData(50).ToList(); model.ForEach(x => { if(x.Color.Equals("Black") || x.Color.Equals("White")) { x.Color = string.Format(" {0} ", x.Color); } }); return View(model); } } }
PreserveWhiteSpace.cshtml
@using C1.Web.Mvc.Grid @model IEnumerable<Sale> @{ ControlOptions optionsModel = ViewBag.DemoOptions; ViewBag.DemoSettings = true; } @(Html.C1().FlexGrid<Sale>() .Id("ovFlexGrid") .AutoGenerateColumns(false) .CssClass("grid") .IsReadOnly(true) .Bind(bl => bl.Bind(Model)) .PreserveWhiteSpace(Convert.ToBoolean(optionsModel.Options["Preserve White Space"].CurrentValue)) .Columns(bl => { bl.Add(cb => cb.Binding("ID")); bl.Add(cb => cb.Binding("Country")); bl.Add(cb => cb.Binding("Product")); bl.Add(cb => cb.Binding("Color")); bl.Add(cb => cb.Binding("Amount").Format("c")); bl.Add(cb => cb.Binding("Amount2").Format("c")); }) ) @section Settings{ @Html.Partial("_OptionsMenu", optionsModel) } @section Summary{ <p>@Html.Raw(Resources.FlexGrid.PreserveWhiteSpace_Text0)</p> } @section Description{ <p>@Html.Raw(Resources.FlexGrid.PreserveWhiteSpace_Text0)</p> <p>@Html.Raw(Resources.FlexGrid.PreserveWhiteSpace_Text1)</p> }
Documentation