Editable Tree Grids
If you use FlexGrid's childItemsPath property to show the data as a tree, the resulting grid will be read-only by default. This happens because every row in a tree is a GroupRow, and group rows are read-only by default.
If you want your tree to be editable, handle the loadedRows event to set the isReadOnly property of every row to false.
You can still control which columns are editable using the column's isReadOnly property or the beginningEdit event.
For example, the grid below allows users to edit cells in the 'hours' and 'rate' columns:
name
hours
rate
Jack Smith
check1
hourly
30.00
15.00
overtime
10.00
20.00
bonus
5.00
30.00
check2
hourly
20.00
18.00
overtime
20.00
24.00
Jack Smith
check1
hourly
30.00
15.00
overtime
10.00
20.00
bonus
5.00
30.00
check2
hourly
20.00
18.00
overtime
20.00
24.00
Jane Smith
check1
hourly
30.00
15.00
overtime
10.00
20.00
bonus
5.00
30.00
check2
hourly
20.00
18.00
overtime
20.00
24.00
name
hours
rate
0
- C1FlexGrid/EditableTreeGrids.js
- C1FlexGrid/EditableTreeGrids.css
- EditableTreeGridsController.cs
- EditableTreeGrids.cshtml
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 | // This file locates: "Scripts/Lesson/C1FlexGrid/EditableTreeGrids.js". c1.documentReady(function () { // workers tree data (heterogeneous collection) var workers = [{ name: 'Jack Smith' , checks: [{ name: 'check1' , earnings: [ { name: 'hourly' , hours: 30.0, rate: 15.0 }, { name: 'overtime' , hours: 10.0, rate: 20.0 }, { name: 'bonus' , hours: 5.0, rate: 30.0 } ] }, { name: 'check2' , earnings: [ { name: 'hourly' , hours: 20.0, rate: 18.0 }, { name: 'overtime' , hours: 20.0, rate: 24.0 } ] }] }, { name: 'Jack Smith' , checks: [{ name: 'check1' , earnings: [ { name: 'hourly' , hours: 30.0, rate: 15.0 }, { name: 'overtime' , hours: 10.0, rate: 20.0 }, { name: 'bonus' , hours: 5.0, rate: 30.0 } ] }, { name: 'check2' , earnings: [ { name: 'hourly' , hours: 20.0, rate: 18.0 }, { name: 'overtime' , hours: 20.0, rate: 24.0 } ] }] }, { name: 'Jane Smith' , checks: [{ name: 'check1' , earnings: [ { name: 'hourly' , hours: 30.0, rate: 15.0 }, { name: 'overtime' , hours: 10.0, rate: 20.0 }, { name: 'bonus' , hours: 5.0, rate: 30.0 } ] }, { name: 'check2' , earnings: [ { name: 'hourly' , hours: 20.0, rate: 18.0 }, { name: 'overtime' , hours: 20.0, rate: 24.0 } ] }] }]; // workers tree var workersGrid = wijmo.Control.getControl( '#workersGrid' ); workersGrid.loadedRows.addHandler(function (s, e) { s.rows.forEach(function (row) { row.isReadOnly = false ; }) }); workersGrid.beginningEdit.addHandler(function (s, e) { var item = s.rows[e.row].dataItem, binding = s.columns[e.col].binding; if (!(binding in item)) { // property not on this item? e.cancel = true ; // can't edit! } }); workersGrid.childItemsPath = [ 'checks' , 'earnings' ]; workersGrid.itemsSource = workers; }); |
1 2 3 4 5 6 7 8 9 10 | // This file locates: "Content/css/Lesson/C1FlexGrid/EditableTreeGrids.css". .wj-flexgrid { max-height: 220px; } .wj-cell.wj-group { border: none; } .wj-cell.wj-group:not(.wj-state-selected):not(.wj-state-multi-selected) { background-color: white; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Web.Mvc; namespace LearnMvcClient.Controllers { public partial class C1FlexGridController : Controller { // GET: EditableTreeGrids public ActionResult EditableTreeGrids() { return View(); } } } |
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 | < h1 > @Html .Raw(Resources.C1FlexGrid.EditableTreeGrids_Title) </ h1 > < p > @Html .Raw(Resources.C1FlexGrid.EditableTreeGrids_Text1) </ p > < p > @Html .Raw(Resources.C1FlexGrid.EditableTreeGrids_Text2) </ p > < p > @Html .Raw(Resources.C1FlexGrid.EditableTreeGrids_Text3) </ p > < p > @Html .Raw(Resources.C1FlexGrid.EditableTreeGrids_Text4) </ p > @ (Html.C1().FlexGrid().Id( "workersGrid" ) .HeadersVisibility(C1.Web.Mvc.Grid.HeadersVisibility.Column) .SelectionMode(C1.Web.Mvc.Grid.SelectionMode.Row) .AutoGenerateColumns( false ) .Columns(cs=> { cs.Add().Binding( "name" ).IsReadOnly( true ); cs.Add().Binding( "hours" ).DataType(C1.Web.Mvc.Grid.DataType.Number).Format( "n2" ); cs.Add().Binding( "rate" ).DataType(C1.Web.Mvc.Grid.DataType.Number).Format( "n2" ); }) ) |