FlexGrid
ShowCase
This view shows basic features of FlexGrid for ASP.NET MVC.
Features
Drag columns here to create Groups
ID
Start
Country
Price
History
Color
Change
Rank
Active
Product
Discount
End Time
1
Jan 25 2025
German
$1,030.17
Green
$581.61
Gadget
14%
12:00
2
Feb 25 2025
Italy
$3,499.71
Green
($4,673.75)
Gadget
13%
01:30
ID
Start
Country
Price
History
Color
Change
Rank
Active
Product
Discount
End Time
0
loading...
Settings
Description
FlexGrid for ASP.NET MVC is new version of the FlexGrid control, which is more flexible and powerful than ever.
This grid allows you to select, edit, sort, group, filter and page data. Additionally, this versatile FlexGrid control lets you format
data and easily visualize the hierarchical data. Performance is a vital attribute of FlexGrid, therefore, the core control is
lightweight and fast. For complex features the control uses extensions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | using System.Collections; using System.Globalization; using System.Linq; using System.Web.Mvc; using C1.Web.Mvc; using MvcExplorer.Models; using System.Collections.Generic; using System; using C1.Web.Mvc.Serialization; namespace MvcExplorer.Controllers { public partial class FlexGridController : Controller { private static List<SaleShowCase> model; private readonly ControlOptions _showcaseOption = new ControlOptions { Options = new OptionDictionary { { "Data Size" , new OptionItem{Values = new List< string > { "5 Rows" , "50 Rows" , "500 Rows" , "5000 Rows" , "50000 Rows" , "100000 Rows" },CurrentValue = "500 Rows" }}, { "Lazy Render" , new OptionItem{Values = new List< string > { "True" , "False" },CurrentValue = "True" }} } }; public ActionResult ShowCase(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); } } _showcaseOption.LoadPostData(data); model = Sale.GetData(getDataSize()).Select(x => SaleShowCase.FromSale(x)).ToList(); ViewBag.DemoOptions = _showcaseOption; ViewBag.Countries = FullCountry.GetCountries(); ViewBag.Products = ProductObject.GetProductObjects(); ViewBag.Colors = ColorObject.GetColorObjects(); Theme.CurrentTheme = Themes.CleanLight; return View(model); } public ActionResult GridShowCaseUpdate([C1JsonRequest]CollectionViewEditRequest<Sale> requestData) { return this .C1Json(CollectionViewHelper.Edit(requestData, sale => { string error = string .Empty; bool success = true ; try { var fSale = model.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; fSale.Discount = sale.Discount; } catch (Exception e) { error = e.Message; success = false ; } return new CollectionViewItemResult<Sale> { Error = error, Success = success, Data = sale }; }, () => model)); } private int getDataSize() { int dataSize = 0; var dataSizeOption = _showcaseOption.Options[ "Data Size" ].CurrentValue; switch (dataSizeOption) { case "5 Rows" : dataSize = 5; break ; case "50 Rows" : dataSize = 50; break ; case "500 Rows" : dataSize = 500; break ; case "5000 Rows" : dataSize = 5000; break ; case "50000 Rows" : dataSize = 50000; break ; case "100000 Rows" : dataSize = 100000; break ; case "500000 Rows" : dataSize = 500000; break ; case "1000000 Rows" : dataSize = 1000000; break ; } return dataSize; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | @using C1.Web.Mvc.Grid @model IEnumerable< SaleShowCase > @ { ControlOptions optionsModel = ViewBag.DemoOptions; ViewBag.DemoSettings = true ; List< FullCountry > countries = ViewBag.Countries; List< ProductObject > products = ViewBag.Products; List< ColorObject > colors = ViewBag.Colors; } @Scripts .Render( "~/jquery" ) @Scripts .Render( "~/jqueryval" ) <script src="~/Scripts/jszip.js"> </script> < link href = "https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/3.1.0/css/flag-icon.css" rel = "stylesheet" /> < link href = "~/Content/css/showcase.css" rel = "stylesheet" /> <!--START: Cell templates--> <script type="text/template" id="edtDate"> @ (Html.C1().InputDate() .Id( "dateEditor" ) .Format( "MM/dd/yyyy" ) .Min(Convert.ToDateTime( "01/01/2000" )) .Max(Convert.ToDateTime( "01/01/2030" )) .IsRequired( true ) .CssStyle( "width" , "100%" ) .TemplateBind( "Value" , "Start" ) .ToTemplate() ) </script> <script id="edtTime" type="text/template"> @ (Html.C1().InputTime() .Id( "timeEditor" ) .Format( "hh:mm" ) .Step(30) .IsRequired( true ) .CssStyle( "width" , "100%" ) .TemplateBind( "Value" , "End" ) .ToTemplate() ) </script> <script id="countryShowing" type="text/template"> < span class = 'flag-icon flag-icon-{{CountryFlag}}' ></ span > < span >{{Country}}</ span > </script> <script type="text/template" id="colorShowing"> < span class = "color-tile" style = "background: {{Color}}" ></ span > {{Color}} </script> <script id="detailTemplate" type="text/template"> < table class = "detail-row" > < tr > < td >Size</ td > < td >: {{ProductDetail.Size}}</ td > </ tr > < tr > < td >Weight</ td > < td >: {{ProductDetail.Weight}}</ td > </ tr > < tr > < td >Quantity</ td > < td >: {{ProductDetail.Quantity}}</ td > </ tr > < tr > < td >Description</ td > < td >: {{ProductDetail.Description}}</ td > </ tr > </ table > </script> <!--END: Cell templates--> < div id = "control-nav-tabs" class = "nav nav-tabs ui-helper-clearfix mob-hide-1" > < div > < a >Data</ a > < div class = "tab-pane pane-content mob-hide-1" > < div class = "flex-container" > < div > @Html .Partial( "_OptionsMenu" , optionsModel)</ div > < div >Search: < span id = "theSearch" style = "width:300px;" ></ span ></ div > < div class = "seperate" ></ div > < div > < div >< img src = "~/Content/images/icons/Columns.png" width = "20" height = "20" class = "export-img" id = "column-picker" />Columns</ div > < div style = "display:none" > < div id = "theColumnPicker" class = "column-picker" ></ div > </ div > </ div > </ div > </ div > </ div > < div > < a >Export</ a > < div class = "tab-pane pane-content mob-hide-1" > < div class = "flex-container" > < div > < img src = "~/Content/images/icons/Excel.png" width = "20" height = "20" id = "export-excel" class = "export-img" />Excel</ div > < div > < img src = "~/Content/images/icons/Csv.png" width = "20" height = "20" id = "export-csv" class = "export-img" />Csv</ div > < div > < img src = "~/Content/images/icons/pdf.png" width = "20" height = "20" id = "export-pdf" class = "export-img" />PDF</ div > </ div > </ div > </ div > </ div > @Html .C1().TabPanel( "#control-nav-tabs" ) @ (Html.C1().FlexGrid< SaleShowCase >() .Id( "theFlexGrid" ) .ShowGroupPanel(s => s .MaxGroups(3) .Placeholder( string .Format( "{0}" , Html.Raw(Resources.FlexGrid.GroupPanel_Placeholder1))) ) .ShowDetailRow(d => d.DetailRowTemplateId( "detailTemplate" ).DetailVisibilityMode(DetailVisibilityMode.ExpandMulti).IsAnimated( false )) .PinningType(PinningType.SingleColumn) .AutoGenerateColumns( false ) .SortingType(AllowSorting.SingleColumn) .SelectionMode(SelectionMode.CellRange) .Bind(bl => bl.InitialItemsCount(Convert.ToBoolean(optionsModel.Options[ "Lazy Render" ].CurrentValue) ? 100 : ( int ?) null ).Bind(Model).OnClientQueryData( "collectingQueryData" ).Update(Url.Action( "GridShowCaseUpdate" ))) .CssClass( "grid" ) .CopyHeaders(CopyHeader.Column) .BigCheckboxes( true ) .LazyRender(Convert.ToBoolean(optionsModel.Options[ "Lazy Render" ].CurrentValue)) .Columns(bl => { bl.Add(cb => cb.Binding( "ID" ).IsReadOnly( true )); bl.Add(cb => cb.Binding( "Start" ).Format( "MMM d yyyy" ).CellTemplate(ctp => ctp.EditTemplateId( "edtDate" ))); bl.Add(cb => cb.Binding( "Country" ).Header( "Country" ).Width( "145" ).CellTemplate(ctb => ctb.TemplateId( "countryShowing" )) .DataMap(dm => dm.DisplayMemberPath( "Name" ) .SelectedValuePath( "Name" ) .SortByDisplayValues( true ) .Bind(countries))); bl.Add(cb => cb.Binding( "Amount2" ).Header( "Price" ).Format( "c" )); bl.Add(cb => cb.Binding( "History" ).IsReadOnly( true ).Width( "180" ).TemplateFunction( "createSparkline" )); bl.Add(cb => cb.Binding( "Color" ).Width( "145" ).CellTemplate(ctb => ctb.TemplateId( "colorShowing" )) .DataMap(dm => dm.DisplayMemberPath( "Name" ) .SelectedValuePath( "Name" ) .SortByDisplayValues( true ) .Bind(colors))); bl.Add(cb => cb.Binding( "Amount" ).Header( "Change" ).IsReadOnly( true ).Format( "c" ).Template( "<span class=${item && item.Amount > 0 ? 'change-up' : 'change-down'}>${text}</span>" )); bl.Add(cb => cb.Binding( "Rank" ).Width( "150" ).Align( "center" ).CssClass( "custom-rating" ).TemplateFunction( "createRating" )); bl.Add(cb => cb.Binding( "Active" )); bl.Add(cb => cb.Binding( "Product" ).Width( "145" ) .DataMap(dm => dm.DisplayMemberPath( "Name" ) .SelectedValuePath( "Name" ) .SortByDisplayValues( true ) .Bind(products))); bl.Add(cb => cb.Binding( "Discount" ).Format( "p0" )); bl.Add(cb => cb.Binding( "End" ).Header( "End Time" ).Format( "hh:mm" ).IsRequired( false ).CellTemplate(ctp => ctp.EditTemplateId( "edtTime" ))); }) .RefreshOnEdit( true ) .Filterable< SaleShowCase >(fl => fl.DefaultFilterType(FilterType.Both).ColumnFilters(cfsb => { cfsb.Add(cfb => cfb.Column( "History" ).FilterType(FilterType.None)); })) ) @ (Html.C1().FlexGridSearch( "#theSearch" ) .Grid( "theFlexGrid" ) .Placeholder( string .Format( "{0}" , Html.Raw(Resources.FlexGrid.EnterTextSearch_Text0))) ) @section Summary{ < p > @Html .Raw(Resources.FlexGrid.Index_Text0)</ p > } @section Description{ @Html .Raw(Resources.FlexGrid.Index_Text1) } @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 > } } // #START: TEMPLATE FUNCTION function createRating(CellMaker) { return CellMaker.makeRating({ range: [0, 5] }); } function createSparkline(CellMaker) { return CellMaker.makeSparkline({ markers: wijmo.grid.cellmaker.SparklineMarkers.High | wijmo.grid.cellmaker.SparklineMarkers.Low }); } // #END: TEMPLATE FUNCTION c1.documentReady( function () { var grid = wijmo.Control.getControl( '#theFlexGrid' ); //#START: COLUMNS PICKER let theColumnPicker = new wijmo.input.MultiSelectListBox( '#theColumnPicker' , { itemsSource: grid.columns, checkedMemberPath: 'visible' , displayMemberPath: 'header' , showFilterInput: true , showSelectAllCheckbox: true , lostFocus: function () { wijmo.hidePopup(theColumnPicker.hostElement) }, checkedItemsChanged: function (sender) { grid.columns.forEach( function (item) { item.visible = false ; }); sender.checkedItems.forEach( function (item) { grid.columns.getColumn(item.binding).visible = true ; }); } }); // // show the column picker when the user clicks the top-left cell document.getElementById( 'column-picker' ).addEventListener( "click" , function (e) { let host = theColumnPicker.hostElement; wijmo.showPopup(host, e.target, false , true , false ); theColumnPicker.focus(); }); //#END: COLUMNS PICKER //#START: EXPORT //Excel document.getElementById( "export-excel" ).addEventListener( "click" , function () { wijmo.grid.xlsx.FlexGridXlsxConverter.save(grid, { scaleMode: wijmo.grid.pdf.ScaleMode.PageWidth, includeColumnHeaders: true , includeCellStyles: false , }, 'FlexGrid.xlsx' ); }); //Pdf document.getElementById( "export-pdf" ).addEventListener( "click" , function () { wijmo.grid.pdf.FlexGridPdfConverter.export(grid, 'FlexGrid.pdf' , { scaleMode: wijmo.grid.pdf.ScaleMode.PageWidth, documentOptions: { pageSettings: { layout: wijmo.pdf.PdfPageOrientation.Portrait }, header: { declarative: { text: '\t&[Page]\\&[Pages]' } }, footer: { declarative: { text: '\t&[Page]\\&[Pages]' } } }, styles: { cellStyle: { backgroundColor: '#ffffff' , borderColor: '#c6c6c6' }, altCellStyle: { backgroundColor: '#f9f9f9' }, groupCellStyle: { backgroundColor: '#dddddd' }, headerCellStyle: { backgroundColor: '#eaeaea' } } }); }); //csv //function for converting CSV string into a downloadable file function exportFile(csv, fileName) { var fileType = 'txt/csv;charset=utf-8' ; if (navigator.msSaveBlob) { // IE navigator.msSaveBlob( new Blob([csv], { type: fileType }), fileName); } else { var e = document.createElement( 'a' ); e.setAttribute( 'href' , 'data:' + fileType + ',' + encodeURIComponent(csv)); e.setAttribute( 'download' , fileName); e.style.display = 'none' ; document.body.appendChild(e); e.click(); document.body.removeChild(e); } } //export grid to CSV document.getElementById( "export-csv" ).addEventListener( "click" , function () { var rng = new wijmo.grid.CellRange(0, 0, grid.rows.length - 1, grid.columns.length - 1), csv = grid.getClipString(rng, true , true ); exportFile(csv, 'FlexGrid.csv' ); }); //#END: EXPORT }); </script> } |