Custom Grouping Example for Blazor

Nevron NOV Grid for Blazor ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All Blazor Grid examples are also available as a stand-alone Visual Studio solution in C#, which you can download from the links below.

Custom Grouping Example for Blazor Description

Demonstrates custom grouping, custom group header content and custom group row cells.

In this example we are grouping fictional emails by the Received field. However, since the condition for grouping is complex, we are using the NCustomRowValue to provide a custom row grouping condition.

The example also demonstrates how to create custom GroupRow cells. Since the email group values are instances of the ENMailGroup enumeration, the CreateGroupRowCellsDelegate is handled to provide a string representation for them.

The example also demonstrates how to override the CreateGroupingHeaderContentDelegate to provide a custom grouping rule header content. In example we have created, Received label serves as header content for the custom grouping rule.


Custom Grouping Example

C# Custom Grouping Example Code for Nevron Grid for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Data;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Grid;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NCustomGroupingExample";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

        #region Example

        public NWidget CreateExampleContent()
        {
            // store current date time
            m_Now = DateTime.Now;

            // create a view and get its grid
            NTableGridView view = new NTableGridView();
            NTableGrid grid = view.Grid;

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

            // create a grouping rule with a custom row value.
            // NOTE: The RowValue associated with each grouping rule, returns an object for each row of the data source.
            // the rows in the data source are grouped according to that object.
            // The NCustomRowValue provides a delegate that help you return a custom object object for each data source row.
            // In our example the NCustomRowValue returns a member of the ENMailGroup enumeraiton for each record, depending on its Received row value.
            NCustomRowValue customRowValue = new NCustomRowValue();
            customRowValue.Description = "Received";
            customRowValue.GetRowValueDelegate = GetRowValueDelegate;

            // NOTE: The NGroupingRule provides the following events:
            // CreateGroupRowCells - raised when the grid needs to create the cells of the group row.
            // CreateGroupingHeaderContent - raised when the grid needs to create a grouping header content for the grouping in the groupings panel.
            NGroupingRule groupingRule = new NGroupingRule();
            groupingRule.RowValue = customRowValue;
            groupingRule.CreateGroupRowCellsDelegate = delegate(NGroupingRuleCreateGroupRowCellsArgs arg)
            {
                int groupValue = Convert.ToInt32(arg.GroupRow.GroupValue);
                string text = NStringHelpers.InsertSpacesBeforeUppersAndDigits(((ENMailGroup)groupValue).ToString());
                return new NGroupRowCell[] { new NGroupRowCell(text) };
            };

            groupingRule.CreateGroupingHeaderContentDelegate = delegate(NGroupingRule theGroupingRule)
            {
                return new NLabel("Received");
            };

            grid.GroupingRules.Add(groupingRule);

            return view;
        }


        public NWidget CreateExampleControls()
        {
            return null;
        }
        public string GetExampleDescription()
        {
            return @"

Demonstrates custom grouping, custom group header content and custom group row cells.

In this example we are grouping fictional emails by the Received field. However, since the condition for grouping is complex, we are using the NCustomRowValue to provide a custom row grouping condition.

The example also demonstrates how to create custom GroupRow cells. Since the email group values are instances of the ENMailGroup enumeration, the CreateGroupRowCellsDelegate is handled to provide a string representation for them.

The example also demonstrates how to the CreateGroupingHeaderContentDelegate to provide a custom grouping rule header content. In example we have created, Received label serves as header content for the custom grouping rule.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Grid Grouping", "https://www.nevron.com/docs/openvision/grid-grouping.html"), ("Grid Data Processing Overview", "https://www.nevron.com/docs/openvision/grid-data-processing-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields DateTime m_Now; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Custom Grouping Example for Blazor Solution