FlexGrid
Boolean Checker
Use the BooleanChecker extender to add checkboxes to groups and column header of boolean column for checking all values in groups or column.
Features
Sample
Settings
Description
In this sample, the BooleanChecker is attached to "Active" column for checking all active values.
To show checkboxes in groups header, need setting Aggregate property of the "Active" column as Aggregate.First.
Note that the BooleanChecker only works with the boolean column. Therefore, with remote data binding, you should manually set the DataType of the column as DataType.Boolean.
Use the BigCheckboxes property to sets a value that determines whether the checkboxes used to edit boolean columns should extend to cover the whole cell width.
Source
BooleanCheckerController.cs
using C1.Web.Mvc; using MvcExplorer.Models; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using C1.Web.Mvc.Serialization; namespace MvcExplorer.Controllers { public partial class FlexGridController : Controller { private static List<Sale> _source = Sale.GetData(20).ToList<Sale>(); public ActionResult BooleanChecker() { ViewBag.DemoSettingsModel = new ClientSettingsModel { Settings = new Dictionary<string, object[]> { {"ShowCheckAll", new object[]{"True", "False"}}, {"ShowCheckGroups", new object[]{"True", "False"}} } }; return View(_source); } public ActionResult GridBooleanCheckerUpdate([C1JsonRequest]CollectionViewEditRequest<Sale> requestData) { return this.C1Json(CollectionViewHelper.Edit(requestData, sale => { string error = string.Empty; bool success = true; var fSale = _source.Find(item => item.ID == sale.ID); fSale.Country = sale.Country; fSale.Amount = sale.Amount; fSale.Start = sale.Start; fSale.End = sale.End; fSale.Product = sale.Product; fSale.Active = sale.Active; fSale.Amount2 = sale.Amount2; fSale.Color = sale.Color; return new CollectionViewItemResult<Sale> { Error = error, Success = success && ModelState.IsValid, Data = fSale }; }, () => _source)); } } }
BooleanChecker.cshtml
@model IEnumerable<Sale> @{ ViewBag.DemoSettings = true; var controlId = (ViewBag.DemoSettingsModel as ClientSettingsModel).ControlId; } @section Scripts{ <script type="text/javascript"> function customChangeShowCheckAll(grid, value) { let selector = c1.getExtenders(grid, wijmo.grid.selector.Selector)[0]; selector.showCheckAll = (value == 'False' ? false : true); grid.endUpdate(); } function customChangeShowCheckGroups(grid, value) { grid.getColumn('Active').aggregate = (value == 'True' ? 'First' : 'None'); grid.endUpdate(); } </script> } @(Html.C1().FlexGrid<Sale>() .Id(controlId) .AutoGenerateColumns(false) .Bind(bl => bl.Update(Url.Action("GridBooleanCheckerUpdate")) .Bind(Model)) .GroupBy("Country").ShowGroups(true) .Columns(bl => { bl.Add(cb => cb.Binding("ID").Width("0.4*").IsReadOnly(true)); bl.Add(cb => cb.Binding("Start").Header("Date").Width("*").Format("d")); bl.Add(cb => cb.Binding("End").Header("Time").Width("*").Format("t")); bl.Add(cb => cb.Binding("Country").Width("1.5*")); bl.Add(cb => cb.Binding("Product").Width("1.5*")); bl.Add(cb => cb.Binding("Amount").Format("n2").Width("1.5*")); bl.Add(cb => cb.Binding("Amount2").Format("n2").Width("1.5*")); bl.Add(cb => cb.Binding("Color").Width("1.5*")); bl.Add(cb => cb.Binding("Active").Width("1.5*").Aggregate(C1.Web.Mvc.Grid.Aggregate.First)); }) .CssStyle("height", "500px") .BooleanChecker(bc => bc.Column("Active")) .BigCheckboxes(true) ) @section Summary{ @Html.Raw(Resources.FlexGrid.BooleanChecker_Text0) } @section Description{ <p>@Html.Raw(Resources.FlexGrid.BooleanChecker_Text1)</p> <p>@Html.Raw(Resources.FlexGrid.BigCheckboxes_Text0)</p> }
Documentation