Column Conditional Formatting 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.

Column Conditional Formatting Example for Blazor Description

Demonstrates the conditional column formatting.

Conditional formatting changes the default formatting of column cells, when a certain condition is met. NOV Grid for .NET provides strong support for authoring complex cell conditions.

Besides static fill rules, NOV Grid for .NET also supports gradient background and text fill declarations, that can be defined as a two color or three color gradient.

In this example Price background uses a two-color gradient background fill. The Product Name is has different background fill and font style applied to certain products (Aptax,Joykix,Zun Zimtam and Dingtincof).


Columns Conditional Formatting Example

C# Column Conditional Formatting Example Code for Nevron Grid for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Data;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
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 - NColumnsConditionalFormattingExample";

			// 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()
        {
            // create a view and get its grid
            NTableGridView view = new NTableGridView();
            NTableGrid grid = view.Grid;

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

            // Formatting Rule 1 = applied to the Product Name column.
            // make the Aptax, Joykix, Zun Zimtam,  Dingtincof cell backgrounds LightCoral, with a bold Font
            {
                // create the formatting rule and add it in the "Product Name" column
                NColumn column = grid.Columns.GetColumnByFieldName("Product Name");

                NFormattingRule formattingRule = new NFormattingRule();
                column.FormattingRules.Add(formattingRule);

                // row condition
                NOrGroupRowCondition orCondition = new NOrGroupRowCondition();
                orCondition.Add(new NOperatorRowCondition(new NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Aptax"));
                orCondition.Add(new NOperatorRowCondition(new NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Joykix"));
                orCondition.Add(new NOperatorRowCondition(new NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Zun Zimtam"));
                orCondition.Add(new NOperatorRowCondition(new NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Dingtincof"));
                formattingRule.RowCondition = orCondition;

                // LightCoral background fill declaration
                NBackgroundFillDeclaration backgroundFillDeclaration = new NBackgroundFillDeclaration();
                backgroundFillDeclaration.Mode = ENFillDeclarationMode.Uniform;
                backgroundFillDeclaration.UniformFill = new NColorFill(NColor.LightCoral);
                formattingRule.Declarations.Add(backgroundFillDeclaration);

                // Bold font style declaration
                NFontStyleDeclaration fontStyleDeclaration = new NFontStyleDeclaration();
                fontStyleDeclaration.FontStyle = ENFontStyle.Bold;
                formattingRule.Declarations.Add(fontStyleDeclaration);
            }

            // Formatting Rule 2 = applied to the Product Name column.
            // make the Aptax and Joykix cell backgrounds LightCoral, with a bold Font
            {
                // create the formatting rule and add it in the "Product Name" column
                NColumn column = grid.Columns.GetColumnByFieldName("Price");
                NFormattingRule formattingRule = new NFormattingRule();
                column.FormattingRules.Add(formattingRule);

                // row condition
                formattingRule.RowCondition = new NTrueRowCondition();

                // get price field min and max
                object minPrice, maxPrice;
                int priceFieldIndex = grid.DataSource.GetFieldIndex("Price");
                grid.DataSource.TryGetMin(priceFieldIndex, out minPrice);
                grid.DataSource.TryGetMax(priceFieldIndex, out maxPrice);

                // make a graident fill declaration 
                NBackgroundFillDeclaration backgroundFillDeclaration = new NBackgroundFillDeclaration();
                backgroundFillDeclaration.Mode = ENFillDeclarationMode.TwoColorGradient;
                backgroundFillDeclaration.MinimumValue = Convert.ToDouble(minPrice);
                backgroundFillDeclaration.MaximumValue = Convert.ToDouble(maxPrice);
                backgroundFillDeclaration.BeginColor = NColor.Green;
                backgroundFillDeclaration.EndColor = NColor.Red;
                formattingRule.Declarations.Add(backgroundFillDeclaration);
            }

            return view;
        }

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

Demonstrates the conditional column formatting.

Conditional formatting changes the default formatting of column cells, when a certain condition is met. NOV Grid for .NET provides strong support for authoring complex cell conditions.

Besides static fill rules, NOV Grid for .NET also supports gradient background and text fill declarations, that can be defined as a two color or three color gradient.

In this example Price background uses a two-color gradient background fill. The Product Name is has different background fill and font style applied to certain products (Aptax,Joykix,Zun Zimtam and Dingtincof).

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Grid Column Conditional Formatting", "https://www.nevron.com/docs/openvision/grid-column-conditional-formatting.html"), ("Grid Row Conditions", "https://www.nevron.com/docs/openvision/grid-row-conditions.html"), ("Grid Column Formats", "https://www.nevron.com/docs/openvision/grid-column-formats.html"), ("Grid Row Values", "https://www.nevron.com/docs/openvision/grid-row-values.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Column Conditional Formatting Example for Blazor Solution