Example #1
0
        NSortingRule CreateTotalSortingRule(NTableGrid grid)
        {
            NColumn salesColumn = grid.Columns.GetColumnByFieldName("Sales");
            NColumn priceColumn = grid.Columns.GetColumnByFieldName("Price");

            // create a sorting rule that sorts by the Total value
            string quantityFieldName = grid.CreateFormulaFieldName("Quantity");
            string priceFieldName    = grid.CreateFormulaFieldName("Price");

            NSortingRule sortingRule = NSortingRule.FromFormula(null, priceFieldName + "*" + quantityFieldName, ENSortingDirection.Ascending);

            sortingRule.Column = salesColumn;
            return(sortingRule);
        }
Example #2
0
        protected override NWidget CreateExampleContent()
        {
            m_GridView = new NTableGridView();
            NTableGrid grid = m_GridView.Grid;

            // bind the grid to the data source
            grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource();

            // add a formula column
            m_TotalColumn       = new NFormulaCalculatedColumn();
            m_TotalColumn.Title = "Total";
            string fx = grid.CreateFormulaFieldName("Price") + "*" + grid.CreateFormulaFieldName("Quantity");

            m_TotalColumn.Formula = fx;
            m_TotalColumn.Format.BackgroundFill = new NColorFill(NColor.SeaShell);
            grid.Columns.Add(m_TotalColumn);

            return(m_GridView);
        }
        protected override NWidget CreateExampleContent()
        {
            NTableGridView gridView = new NTableGridView();
            NTableGrid     grid     = gridView.Grid;

            // bind the grid to the data source
            grid.DataSource = NDummyDataSource.CreateCompanySalesDataSource();

            // create a grouping rule that groups by the company field value first
            // note that in order to indicate the grouping in the grouping panel, the rule must reference the respective column
            NColumn          companyColumn = grid.Columns.GetColumnByFieldName("Company");
            string           fx1           = grid.CreateFormulaFieldName("Company");
            NFormulaRowValue fxRowValue    = new NFormulaRowValue(fx1);
            NGroupingRule    groupingRule1 = new NGroupingRule(companyColumn, fxRowValue, ENSortingDirection.Ascending);

            grid.GroupingRules.Add(groupingRule1);

            // create a grouping rule that groups by sales larger than 1000 next
            // note that in order to indicate the grouping in the grouping panel, the rule must reference the respective column
            string        fx2           = grid.CreateFormulaFieldName("Sales") + ">1000";
            NColumn       salesColumn   = grid.Columns.GetColumnByFieldName("Sales");
            NGroupingRule groupingRule2 = NGroupingRule.FromFormula(salesColumn, fx2);

            groupingRule2.CreateGroupRowCellsDelegate += delegate(NGroupingRuleCreateGroupRowCellsArgs arg)
            {
                bool   groupValue = (bool)((NVariant)arg.GroupRow.GroupValue);
                string text       = groupValue? "Sales greater than 1000" : "Sales less than or equal to 1000";
                return(new NGroupRowCell[] { new NGroupRowCell(text) });
            };
            grid.GroupingRules.Add(groupingRule2);

            // alter some view preferences
            grid.AllowSortColumns   = true;
            grid.AlternatingRows    = true;
            grid.RowHeaders.Visible = true;

            return(gridView);
        }