FlexGrid
Preserve White Space
The sampe shows how to make the grid should 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 should 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 C1.Web.Mvc; using C1.Web.Mvc.Serialization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using MvcExplorer.Models; using System.Collections.Generic; 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(IFormCollection collection) { _preserveWhiteSpaceDataModel.LoadPostData(collection); ViewBag.DemoOptions = _preserveWhiteSpaceDataModel; return View(); } public ActionResult PreserveWhiteSpace_Bind([C1JsonRequest] CollectionViewRequest<Sale> requestData) { var extraData = requestData.ExtraRequestData .ToDictionary(kvp => kvp.Key, kvp => new StringValues(kvp.Value.ToString())); var data = new FormCollection(extraData); _columnPinningDataModel.LoadPostData(data); 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 this.C1Json(CollectionViewHelper.Read(requestData, model)); } } }
PreserveWhiteSpace.cshtml
@using C1.Web.Mvc.Grid @model IEnumerable<Sale> @{ ControlOptions optionsModel = ViewBag.DemoOptions; ViewBag.DemoSettings = true; } @section Scripts{ <script> function collectingQueryData(sender, e) { if (e.extraRequestData == null) { e.extraRequestData = {}; } @foreach (var menuName in optionsModel.Options.Keys.Select(ControlOptions.ToOptionName)) { <text> e.extraRequestData["@(menuName)"] = '@(optionsModel.Options[menuName].CurrentValue)'; </text> } } </script> } <c1-flex-grid id="ovFlexGrid" auto-generate-columns="false" class="grid" is-read-only="true" preserve-white-space="@Convert.ToBoolean(optionsModel.Options["Preserve White Space"].CurrentValue)"> <c1-flex-grid-column binding="ID"></c1-flex-grid-column> <c1-flex-grid-column binding="Country"></c1-flex-grid-column> <c1-flex-grid-column binding="Product"></c1-flex-grid-column> <c1-flex-grid-column binding="Color"></c1-flex-grid-column> <c1-flex-grid-column binding="Amount" format="c"></c1-flex-grid-column> <c1-flex-grid-column binding="Amount2" format="c"></c1-flex-grid-column> <c1-items-source read-action-url="@Url.Action("PreserveWhiteSpace_Bind")" query-data="collectingQueryData"></c1-items-source> </c1-flex-grid> @section Settings{ @await Html.PartialAsync("_OptionsMenu", optionsModel) } @section Summary{ <p>@Html.Raw(FlexGridRes.PreserveWhiteSpace_Text0)</p> } @section Description{ <p>@Html.Raw(FlexGridRes.PreserveWhiteSpace_Text0)</p> <p>@Html.Raw(FlexGridRes.PreserveWhiteSpace_Text1)</p> }
Documentation