Custom Column Format 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 Column Format Example for Blazor Description

Demonstrates custom column formatting.

The custom column format is represented by the NCustomColumnFormat class. It exposes a set of delegates that you can hook to create your own widgets that represent the row values.

In this example we are using the NOV Chart for .NET to display Double[] values.


Custom Column Formats Example

C# Custom Column Format Example Code for Nevron Grid for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
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 - NCustomColumnFormatsExample";

			// 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()
        {
            NMemoryDataTable dataTable = new NMemoryDataTable(
                new NFieldInfo("Company", typeof(String)),
                new NFieldInfo("RegionSales", typeof(Double[])));

            Random rnd = new Random();
            for (int i = 0; i < 1000; i++)
            {
                Double[] arr = new Double[10];
                for (int j = 0; j < 10; j++)
                {
                    arr[j] = rnd.Next(100);
                }

                dataTable.AddRow(NDummyDataSource.RandomCompanyName(), arr);
            }

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

            grid.AutoCreateColumn += delegate(NAutoCreateColumnEventArgs arg)
            {
                if (arg.DataColumn.FieldName == "RegionSales")
                {
                    NCustomColumnFormat pieColumnFormat = new NCustomColumnFormat();
                    
                    pieColumnFormat.FormatDefaultCellDelegate = delegate(NColumnCell cell)
                    {
                        NWidget widget = new NWidget();
                        widget.PreferredSize = new NSize(400, 300);
                    };

                    pieColumnFormat.CreateCellViewDelegate = delegate(NColumnCell cell, object value)
                    {
                        double[] values = (double[])value;

                        NChartView chartView = new NChartView();
                        chartView.PreferredSize = new NSize(300, 60);

						NCartesianChart cartesianChart = new NCartesianChart();

						NDockLayout.SetDockArea(cartesianChart, ENDockArea.Center);
						chartView.Surface.Content = cartesianChart;

						cartesianChart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
						cartesianChart.Legend = null;

						cartesianChart.Axes[ENCartesianAxis.PrimaryX].Visible = false;
						NCartesianAxis yAxis = cartesianChart.Axes[ENCartesianAxis.PrimaryY];

						NValueScaleLabelStyle labelStyle = new NValueScaleLabelStyle();
						labelStyle.TextStyle.Font = new NFont("Arimo", 8);
						((NLinearScale)yAxis.Scale).Labels.Style = labelStyle;

                        NBarSeries barSeries = new NBarSeries();
						barSeries.DataLabelStyle = new NDataLabelStyle(false);
						barSeries.InflateMargins = false;
                        cartesianChart.Series.Add(barSeries);

                        int count = values.Length;
                        for (int i = 0; i < count; i++)
                        {
                            barSeries.DataPoints.Add(new NBarDataPoint(values[i]));
                        }

                        return chartView;
                    };

                    arg.DataColumn.Format = pieColumnFormat;
                }
            };

            grid.DataSource = new NDataSource(dataTable);
            return view;
        }
        public NWidget CreateExampleControls()
        {
            return null;
        }
        public string GetExampleDescription()
        {
            return @"

Demonstrates custom column formatting.

The custom column format is represented by the NCustomColumnFormat class. It exposes a set of delegates that you can hook to create your own widgets that represent the row values.

In this example we are using the NOV Chart for .NET to display Double[] values.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Grid Column Formats", "https://www.nevron.com/docs/openvision/grid-column-formats.html"), ("Grid Data Columns", "https://www.nevron.com/docs/openvision/grid-data-columns.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) Custom Column Format Example for Blazor Solution

Related Documentation Links