Grouping Example for Blazor

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

Grouping Example for Blazor Description

This example demonstrates how to create schedule groups, how to associate a group to appointments and how to apply grouping to schedule view modes. Each view mode (except for "Timeline") has a default date related grouping, so you can either add a new grouping or insert it before the default one. This will affect the order in which the groupings are applied. Use the radio button on the right to control the grouping order.


Grouping Example

C# Grouping Example Code for Nevron Schedule for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Schedule;
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 - NGroupingExample";

			// 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 simple schedule
			NScheduleViewWithRibbon scheduleViewWithRibbon = new NScheduleViewWithRibbon();
			m_ScheduleView = scheduleViewWithRibbon.View;

			m_ScheduleView.Document.PauseHistoryService();
			try
			{
				InitSchedule(m_ScheduleView.Content);
			}
			finally
			{
				m_ScheduleView.Document.ResumeHistoryService();
			}

			// Return the commanding widget
			return scheduleViewWithRibbon;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();

			stack.Add(new NRadioButton("Time grouping first"));
			stack.Add(new NRadioButton("Group grouping first"));

			NRadioButtonGroup groupingOrderGroup = new NRadioButtonGroup(stack);
			groupingOrderGroup.SelectedIndexChanged += OnRadioGroupSelectedIndexChanged;
			groupingOrderGroup.SelectedIndex = 0;

			return groupingOrderGroup;
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create schedule groups, how to associate a group to appointments and how to apply grouping to schedule view modes. Each view mode (except for ""Timeline"") has a default date related grouping, so you can either add a new grouping or insert it before the default one. This will affect the order in which the groupings are applied. Use the radio button on the right to control the grouping order.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Schedule Grouping Appointments", "https://www.nevron.com/docs/openvision/schedule-grouping-appointments.html"), ("Schedule Grouping Overview", "https://www.nevron.com/docs/openvision/schedule-grouping-overview.html"), ("Schedule Appointments", "https://www.nevron.com/docs/openvision/schedule-appointments.html"), ("Schedule", "https://www.nevron.com/docs/openvision/schedule.html"), }; } #endregion #region Implementation private void InitSchedule(NSchedule schedule) { const string ActivityGroup = "Activity"; const string Work = "Work"; const string Rest = "Rest"; const string Travel = "Travel"; schedule.ViewMode = ENScheduleViewMode.Day; // Add a schedule group schedule.Groups.Add(new NScheduleGroup(ActivityGroup, new string[] { Work, Rest, Travel })); // Add a grouping to each of the view modes schedule.DayViewMode.Groupings.Add(new NGroupGrouping(ActivityGroup)); schedule.WeekViewMode.Groupings.Add(new NGroupGrouping(ActivityGroup)); schedule.MonthViewMode.Groupings.Add(new NGroupGrouping(ActivityGroup)); schedule.TimelineViewMode.Groupings.Add(new NGroupGrouping(ActivityGroup)); // Create the appointments DateTime today = DateTime.Today; schedule.Appointments.Add(CreateAppointment("Travel to Work", today.AddHours(6.5), today.AddHours(7.5), Travel)); schedule.Appointments.Add(CreateAppointment("Meeting with John", today.AddHours(8), today.AddHours(10), Work)); schedule.Appointments.Add(CreateAppointment("Conference", today.AddHours(10.5), today.AddHours(11.5), Work)); schedule.Appointments.Add(CreateAppointment("Lunch", today.AddHours(12), today.AddHours(14), Rest)); schedule.Appointments.Add(CreateAppointment("News Reading", today.AddHours(12.5), today.AddHours(13.5), Rest)); schedule.Appointments.Add(CreateAppointment("Video Presentation", today.AddHours(14.5), today.AddHours(15.5), Work)); schedule.Appointments.Add(CreateAppointment("Web Meeting", today.AddHours(16), today.AddHours(17), Work)); schedule.Appointments.Add(CreateAppointment("Travel back home", today.AddHours(17.5), today.AddHours(19), Travel)); schedule.Appointments.Add(CreateAppointment("Family Dinner", today.AddHours(20), today.AddHours(21), Rest)); } private NAppointment CreateAppointment(string subject, DateTime start, DateTime end, string groupItem) { NAppointment appointment = new NAppointment(subject, start, end); appointment.Groups = new NAppointmentGroupCollection(); appointment.Groups.Add(new NAppointmentGroup("Activity", groupItem)); return appointment; } private void SwapGroupings(NViewMode viewMode) { NGrouping grouping1 = viewMode.Groupings[0]; NGrouping grouping2 = viewMode.Groupings[1]; viewMode.Groupings.Clear(); viewMode.Groupings.Add(grouping2); viewMode.Groupings.Add(grouping1); } #endregion #region Event Handlers private void OnRadioGroupSelectedIndexChanged(NValueChangeEventArgs arg) { int selectedIndex = (int)arg.NewValue; NSchedule schedule = m_ScheduleView.Content; if (selectedIndex == 0) { // Time grouping should be first if (schedule.DayViewMode.Groupings[0] is NGroupGrouping) { SwapGroupings(schedule.DayViewMode); SwapGroupings(schedule.WeekViewMode); SwapGroupings(schedule.MonthViewMode); } } else { // Schedule group grouping should be first if (schedule.DayViewMode.Groupings[0] is NDateRangeGrouping) { SwapGroupings(schedule.DayViewMode); SwapGroupings(schedule.WeekViewMode); SwapGroupings(schedule.MonthViewMode); } } } #endregion #region Fields private NScheduleView m_ScheduleView; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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