|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Column spanning in Blazor Tree Grid Component | Syncfusion |
| 4 | +description: Check out here and learn more details about the Column spanning in the Syncfusion Blazor Tree Grid component. |
| 5 | +platform: Blazor |
| 6 | +control: Tree Grid |
| 7 | +documentation: ug |
| 8 | +--- |
| 9 | + |
| 10 | +# Column spanning in Blazor Tree Grid Component |
| 11 | + |
| 12 | +The column spanning feature in the Syncfusion<sup style="font-size:70%">®</sup> Tree Grid allows automatically merging cells with identical values in the same row across consecutive columns. This significantly enhances readability and delivers a clean, professional look by eliminating repetitive data. |
| 13 | + |
| 14 | +To enable column spanning, set the [AutoSpan](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.TreeGrid.SfTreeGrid-1.html#Syncfusion_Blazor_TreeGrid_SfTreeGrid_1_AutoSpan) property to `AutoSpanMode.Column` in the Tree Grid configuration. |
| 15 | + |
| 16 | +In the following example, cells in rows are automatically merged when they have identical values in consecutive columns. The `AutoSpan` mode in this example can be dynamically changed using the dropdown selector. It is initially set to **Column** mode, allowing you to easily switch between different spanning modes to understand how row and column spanning work in practice. |
| 17 | + |
| 18 | +{% tabs %} |
| 19 | + |
| 20 | +{% highlight razor %} |
| 21 | + |
| 22 | +@using Syncfusion.Blazor.Grids |
| 23 | +@using Syncfusion.Blazor.TreeGrid |
| 24 | +@using Syncfusion.Blazor.DropDowns |
| 25 | +@using Syncfusion.Blazor.Buttons |
| 26 | + |
| 27 | +<div class="form-row alt"> |
| 28 | + <div class="left"> |
| 29 | + <label class="e-option">Select AutoSpan Mode:</label> |
| 30 | + <SfDropDownList TValue="string" TItem="string" |
| 31 | + DataSource="@modes" |
| 32 | + Value="@selectedMode" |
| 33 | + Width="auto"> |
| 34 | + <DropDownListEvents TItem="string" ValueChange="OnModeChanged" TValue="string"></DropDownListEvents> |
| 35 | + </SfDropDownList> |
| 36 | + </div> |
| 37 | +</div> |
| 38 | + <br/> |
| 39 | +<SfTreeGrid @ref="TreeGridInstance" DataSource="@TreeData" IdMapping="Id" EnableHover ParentIdMapping="ParentId" AutoSpan="@currentMode" TreeColumnIndex="1" GridLines="GridLine.Both"> |
| 40 | + <TreeGridColumns> |
| 41 | + <TreeGridColumn Field="Id" HeaderText="ID" Width="80" TextAlign="TextAlign.Center" IsPrimaryKey></TreeGridColumn> |
| 42 | + <TreeGridColumn Field="Name" HeaderText="Developer" Width="150"></TreeGridColumn> |
| 43 | + <TreeGridColumn Field="Slot1" HeaderText="10:00 - 11:00 AM" Width="150" ></TreeGridColumn> |
| 44 | + <TreeGridColumn Field="Slot2" HeaderText="11:00 - 12:00 AM" Width="150"></TreeGridColumn> |
| 45 | + <TreeGridColumn Field="Slot3" HeaderText="12:00 - 13:00 PM" Width="150"></TreeGridColumn> |
| 46 | + <TreeGridColumn Field="Slot4" HeaderText="01:00 - 02:00 PM" Width="150"></TreeGridColumn> |
| 47 | + <TreeGridColumn Field="Slot5" HeaderText="02:00 - 03:00 PM" Width="150"></TreeGridColumn> |
| 48 | + <TreeGridColumn Field="Slot6" HeaderText="03:00 - 04:00 PM" Width="150"></TreeGridColumn> |
| 49 | + <TreeGridColumn Field="Slot7" HeaderText="04:00 - 05:00 PM" Width="150"></TreeGridColumn> |
| 50 | + </TreeGridColumns> |
| 51 | +</SfTreeGrid> |
| 52 | + |
| 53 | + |
| 54 | +@code { |
| 55 | + private AutoSpanMode currentMode = AutoSpanMode.Column; |
| 56 | + private string selectedMode = "Column"; |
| 57 | + private List<string> modes = new() { "None", "Row", "Column", "Horizontal and Vertical" }; |
| 58 | + public SfTreeGrid<DeveloperSchedule> TreeGridInstance; |
| 59 | + public List<DeveloperSchedule> TreeData { get; set; } |
| 60 | + |
| 61 | + protected override void OnInitialized() |
| 62 | + { |
| 63 | + TreeData = DeveloperSchedule.GetTree().ToList(); |
| 64 | + } |
| 65 | + |
| 66 | + private void OnModeChanged(ChangeEventArgs<string, string> args) |
| 67 | + { |
| 68 | + selectedMode = args?.Value ?? "None"; |
| 69 | + currentMode = selectedMode switch |
| 70 | + { |
| 71 | + "Row" => AutoSpanMode.Row, |
| 72 | + "Column" => AutoSpanMode.Column, |
| 73 | + "Horizontal and Vertical" => AutoSpanMode.HorizontalAndVertical, |
| 74 | + _ => AutoSpanMode.None |
| 75 | + }; |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +{% endhighlight %} |
| 80 | + |
| 81 | +{% highlight c# %} |
| 82 | +namespace TreeGridComponent.Data { |
| 83 | + |
| 84 | + public class DeveloperSchedule |
| 85 | + { |
| 86 | + public int Id { get; set; } |
| 87 | + public string Name { get; set; } |
| 88 | + public string Slot1 { get; set; } |
| 89 | + public string Slot2 { get; set; } |
| 90 | + public string Slot3 { get; set; } |
| 91 | + public string Slot4 { get; set; } |
| 92 | + public string Slot5 { get; set; } |
| 93 | + public string Slot6 { get; set; } |
| 94 | + public string Slot7 { get; set; } |
| 95 | + public int? ParentId { get; set; } |
| 96 | + public bool IsExpanded { get; set; } |
| 97 | + |
| 98 | + public static List<DeveloperSchedule> GetTree() |
| 99 | + { |
| 100 | + List<DeveloperSchedule> Developers = new List<DeveloperSchedule> |
| 101 | + { |
| 102 | + new DeveloperSchedule { Id = 1, Name = "Martin", Slot1 = "Feature Dev", Slot2 = "Bug Fixing", Slot3 = "Team Sync", Slot4 = "Lunch Break", Slot5 = "Testing", Slot6 = "Planning", Slot7 = "Code Review", IsExpanded = false }, |
| 103 | + new DeveloperSchedule { Id = 2, ParentId = 1, Name = "Vance", Slot1 = "Bug Fixing", Slot2 = "Bug Fixing", Slot3 = "Team Sync", Slot4 = "Lunch Break", Slot5 = "Planning", Slot6 = "Code Review", Slot7 = "Feature Dev" }, |
| 104 | + new DeveloperSchedule { Id = 3, ParentId = 2, Name = "Charlie", Slot1 = "Team Sync", Slot2 = "Team Sync", Slot3 = "Testing", Slot4 = "Lunch Break", Slot5 = "Feature Dev", Slot6 = "Code Review", Slot7 = "Bug Fixing" }, |
| 105 | + new DeveloperSchedule { Id = 4, Name = "Taylor", Slot1 = "Team Sync", Slot2 = "Bug Fixing", Slot3 = "Planning", Slot4 = "Lunch Break", Slot5 = "Testing", Slot6 = "Bug Fixing", Slot7 = "Planning", IsExpanded = false }, |
| 106 | + new DeveloperSchedule { Id = 5, ParentId = 4, Name = "Anderson", Slot1 = "Testing", Slot2 = "Planning", Slot3 = "Code Review", Slot4 = "Lunch Break", Slot5 = "Bug Fixing", Slot6 = "Testing", Slot7 = "Planning" }, |
| 107 | + new DeveloperSchedule { Id = 6, ParentId = 5, Name = "Chris", Slot1 = "Planning", Slot2 = "Code Review", Slot3 = "Feature Dev", Slot4 = "Lunch Break", Slot5 = "Testing", Slot6 = "Team Sync", Slot7 = "Testing" }, |
| 108 | + new DeveloperSchedule { Id = 7, Name = "Elizabeth", Slot1 = "Code Review", Slot2 = "Feature Dev", Slot3 = "Bug Fixing", Slot4 = "Lunch Break", Slot5 = "Testing", Slot6 = "Code Review", Slot7 = "Planning", IsExpanded = false }, |
| 109 | + new DeveloperSchedule { Id = 8, ParentId = 7, Name = "Robert", Slot1 = "Feature Dev", Slot2 = "Bug Fixing", Slot3 = "Bug Fixing", Slot4 = "Lunch Break", Slot5 = "Testing", Slot6 = "Planning", Slot7 = "Code Review" }, |
| 110 | + new DeveloperSchedule { Id = 9, ParentId = 8, Name = "Smith", Slot1 = "Bug Fixing", Slot2 = "Testing", Slot3 = "Team Sync", Slot4 = "Lunch Break", Slot5 = "Planning", Slot6 = "Planning", Slot7 = "Feature Dev" }, |
| 111 | + new DeveloperSchedule { Id = 10, ParentId = 7, Name = "John", Slot1 = "Scrum", Slot2 = "Team Sync", Slot3 = "Testing", Slot4 = "Lunch Break", Slot5 = "Code Review", Slot6 = "Feature Dev", Slot7 = "Bug Fixing" } |
| 112 | + }; |
| 113 | + return Developers; |
| 114 | + } |
| 115 | + } |
| 116 | +} |
| 117 | +{% endhighlight %} |
| 118 | + |
| 119 | +{% endtabs %} |
| 120 | + |
| 121 | +N> In the above example, notice how cells with identical consecutive values across columns in each row are automatically merged horizontally, creating a cleaner view. For instance, when consecutive time slots have the same activity value, they span across multiple columns. |
| 122 | + |
| 123 | +## Limitations |
| 124 | + |
| 125 | +Column spanning feature is not compatible with all the features which are available in Tree Grid and it has limited features support. Here we have listed out the features which are not compatible with column spanning feature. |
| 126 | + |
| 127 | +* Virtualization |
| 128 | +* Infinite Scrolling |
| 129 | +* Row Drag and Drop |
| 130 | +* Column Virtualization |
| 131 | +* Detail Template |
| 132 | +* Editing |
| 133 | +* Export |
| 134 | + |
| 135 | +## See Also |
| 136 | + |
| 137 | +* [Row spanning in Syncfusion<sup style="font-size:70%">®</sup> TreeGrid](https://blazor.syncfusion.com/documentation/treegrid/rows/row-spanning) |
0 commit comments