protected override NWidget CreateExampleContent() { // create a view and get its grid NTableGridView view = new NTableGridView(); NTableGrid grid = view.Grid; // customize the grid grid.AllowEdit = false; // create the dummy persons data source - we will use it to obtain person names from person ids from it. m_PersonsDataSource = NDummyDataSource.CreatePersonsDataSource(); // bind to data source, but exclude the "PersonId" field from binding grid.AutoCreateColumn += delegate(NAutoCreateColumnEventArgs arg) { if (arg.FieldInfo.Name == "PersonId") { arg.DataColumn = null; } }; grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource(); // create a grouping rule that groups by the PersonId field NGroupingRule groupingRule = new NGroupingRule(); groupingRule.RowValue = new NFieldRowValue("PersonId"); // create a custom grouping header named "Person" groupingRule.CreateGroupingHeaderContentDelegate = delegate(NGroupingRule theGroupingRule) { return(new NLabel("Person")); }; // create custom group row cells that display the person Name and number of orders groupingRule.CreateGroupRowCellsDelegate = delegate(NGroupingRuleCreateGroupRowCellsArgs arg) { // get the person id from the row for which we create row cells. int personId = (int)arg.GroupRow.GroupValue; // get the person name that corresponds to that person id. int idField = m_PersonsDataSource.GetFieldIndex("Id"); NRecordset rs = m_PersonsDataSource.GetOrCreateIndex(idField).GetRecordsForValue(personId); string personName = (string)m_PersonsDataSource.GetValue(rs[0], "Name"); // create the group row cells NGroupRowCell personNameCell = new NGroupRowCell(personName); personNameCell.EndXPosition.Mode = ENSpanCellEndXPositionMode.NextCellBeginX; NGroupRowCell ordersCountCell = new NGroupRowCell("Orders Count:" + arg.GroupRow.Recordset.Count); ordersCountCell.EndXPosition.Mode = ENSpanCellEndXPositionMode.RowEndX; ordersCountCell.BeginXPosition.Mode = ENSpanCellBeginXPositionMode.AnchorToEndX; return(new NGroupRowCell[] { personNameCell, ordersCountCell }); }; grid.GroupingRules.Add(groupingRule); return(view); }
protected override NWidget CreateExampleContent() { // create a view and get its grid NTableGridView view = new NTableGridView(); NTableGrid grid = view.Grid; // customize the grid grid.AllowEdit = false; // bind to data source, but exclude the "PersonId" field from binding grid.AutoCreateColumn += delegate(NAutoCreateColumnEventArgs arg) { if (arg.FieldInfo.Name == "PersonId") { arg.DataColumn = null; } }; grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource(); // create a calculated Total column NCustomCalculatedColumn <double> totalColumn = new NCustomCalculatedColumn <double>(); totalColumn.Title = "Total"; totalColumn.GetRowValueDelegate = delegate(NCustomCalculatedColumnGetRowValueArgs <double> args) { double price = Convert.ToDouble(args.DataSource.GetValue(args.RowIndex, "Price")); int quantity = Convert.ToInt32(args.DataSource.GetValue(args.RowIndex, "Quantity")); return((double)(price * quantity)); }; grid.Columns.Add(totalColumn); // create a grouping rule that groups by the Product Name column NGroupingRule groupingRule = new NGroupingRule(grid.Columns.GetColumnByFieldName("Product Name")); // create a footer summary row for the total total groupingRule.CreateFooterSummaryRowsDelegate = delegate(NGroupingRuleCreateSummaryRowsArgs args) { // get the recordset for the group NRecordset recordset = args.GroupRow.Recordset; // calculate the sum of totals double total = 0; for (int i = 0; i < recordset.Count; i++) { total += Convert.ToDouble(totalColumn.GetRowValue(recordset[i])); } // create the total summary row NSummaryRow totalRow = new NSummaryRow(); totalRow.Cells = new NSummaryCellCollection(); NSummaryCell cell = new NSummaryCell(); cell.BeginXPosition.Mode = ENSpanCellBeginXPositionMode.AnchorToEndX; cell.EndXPosition.Mode = ENSpanCellEndXPositionMode.RowEndX; cell.Content = new NLabel("Grand Total: " + total.ToString("0.00")); totalRow.Cells.Add(cell); return(new NSummaryRow[] { totalRow }); }; grid.GroupingRules.Add(groupingRule); return(view); }