Skip to content

Commit 3bda553

Browse files
Merge pull request #7006 from syncfusion-content/986480-part2
documentation(986480): Updated blazor topic.
2 parents c1304f7 + 3adb140 commit 3bda553

File tree

7 files changed

+730
-526
lines changed

7 files changed

+730
-526
lines changed

blazor-toc.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3057,7 +3057,6 @@
30573057
<li><a href="/blazor/gantt-chart/column-template">Column Template</a></li>
30583058
<li><a href="/blazor/gantt-chart/column-menu">Column Menu</a></li>
30593059
<li><a href="/blazor/gantt-chart/column-chooser">Column Chooser</a></li>
3060-
<li><a href="/blazor/gantt-chart/responsive-columns">Responsive Column</a></li>
30613060
<li><a href="/blazor/gantt-chart/wbs-column">WBS Column</a></li>
30623061
</ul>
30633062
</li>

blazor/gantt-chart/cell-selection.md

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ control: Gantt Chart
77
documentation: ug
88
---
99

10-
# Cell Selection in Blazor Gantt Chart Component
10+
# Cell selection in Blazor Gantt Chart component
1111

12-
Cell selection in the Syncfusion Blazor Gantt Chart allows users to select individual cells in the Tree Grid section, enabling interactions like data inspection or editing. Enable this feature by setting the [GanttSelectionSettings.Mode](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.GanttSelectionSettings.html#Syncfusion_Blazor_Gantt_GanttSelectionSettings_Mode) property to [SelectionMode.Cell](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SelectionMode.html#Syncfusion_Blazor_Grids_SelectionMode_Cell). The data model must include fields like `TaskId`, `TaskName`, `StartDate`, `EndDate`, `Duration`, `Progress`, and optionally `ParentId` for hierarchical tasks. Use the [GetSelectedRowCellIndexes](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.SfGantt-1.html#Syncfusion_Blazor_Gantt_SfGantt_1_GetSelectedRowCellIndexes) method to retrieve selected cell information, which returns an object collection with `CellIndexes` and `RowIndex`. This guide covers single cell selection, multiple cell selection, dynamic selection, and customizing selection actions.
12+
Cell selection in the Gantt Chart component enables interactive selection of specific cells or ranges of cells within the grid. You may select cells using mouse clicks or arrow keys (up, down, left, right). This is useful for highlighting, manipulating, or performing operations on particular gantt chart cells.
1313

14-
## Select single cell
14+
## Single cell selection
1515

16-
Enable single cell selection by setting `GanttSelectionSettings.Mode` to `Cell`. Click a cell in the Tree Grid section to select it. The selected cell is highlighted, and its details can be accessed programmatically.
16+
Single cell selection in the Gantt chart is enabled by setting [GanttSelectionSettings.Mode](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.GanttSelectionSettings.html#Syncfusion_Blazor_Gantt_GanttSelectionSettings_Mode) to **Cell** and [selectionSettings.type](https://ej2.syncfusion.com/angular/documentation/api/gantt/selectionSettings/#type) to **Single**. This allows selecting only one cell at a time.
1717

1818
{% tabs %}
1919
{% highlight razor tabtitle="Index.razor" %}
@@ -24,7 +24,7 @@ Enable single cell selection by setting `GanttSelectionSettings.Mode` to `Cell`.
2424
<SfGantt DataSource="@TaskCollection" Height="450px" Width="700px">
2525
<GanttTaskFields Id="TaskID" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Duration="Duration" Progress="Progress" ParentID="ParentID">
2626
</GanttTaskFields>
27-
<GanttSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Cell"></GanttSelectionSettings>
27+
<GanttSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Cell" Type="Syncfusion.Blazor.Grids.SelectionType.Single"></GanttSelectionSettings>
2828
</SfGantt>
2929

3030
@code {
@@ -68,9 +68,9 @@ Enable single cell selection by setting `GanttSelectionSettings.Mode` to `Cell`.
6868

6969
{% previewsample "https://blazorplayground.syncfusion.com/embed/htreNkhJUikAkJWL?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
7070

71-
## Select multiple cells
71+
## Multiple cell selection
7272

73-
Enable multiple cell selection by setting `GanttSelectionSettings.Mode` to `Cell` and `GanttSelectionSettings.Type` to `Syncfusion.Blazor.Grids.SelectionType.Multiple`. Hold the <kbd>Ctrl</kbd> key and click cells to select multiple cells in the Tree Grid section.
73+
Multiple cell selection in the Gantt Chart is enabled by setting [selectionSettings.mode](https://ej2.syncfusion.com/angular/documentation/api/gantt/selectionSettings/#mode) to **Cell** and [selectionSettings.type](https://ej2.syncfusion.com/angular/documentation/api/gantt/selectionSettings/#type) to **Multiple**. This allows selecting multiple cells at a time by holding the <kbd>Ctrl</kbd> key while clicking on each desired cell.
7474

7575
{% tabs %}
7676
{% highlight razor tabtitle="Index.razor" %}
@@ -126,9 +126,9 @@ Enable multiple cell selection by setting `GanttSelectionSettings.Mode` to `Cell
126126

127127
> **Note**: Multiple cell selection requires <kbd>Ctrl</kbd> + click on Windows or <kbd>Cmd</kbd> + click on Mac. Ensure selections are visible on smaller screens for mobile responsiveness.
128128
129-
## Select cell dynamically
129+
## Single cell selection dynamically
130130

131-
Programmatically select a cell using the [SelectCellAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.SfGantt-1.html#Syncfusion_Blazor_Gantt_SfGantt_1_SelectCellAsync_System_ValueTuple_System_Int32_System_Int32__System_Nullable_System_Boolean__) method, specifying the row and column index. Use a reference to the Gantt component and handle potential errors for invalid indices.
131+
Select a specific cell in the Gantt Chart by calling the [SelectCellAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.SfGantt-1.html#Syncfusion_Blazor_Gantt_SfGantt_1_SelectCellAsync_System_ValueTuple_System_Int32_System_Int32__System_Nullable_System_Boolean__) method and providing the desired row and column indexes as arguments.
132132

133133
{% tabs %}
134134
{% highlight razor tabtitle="Index.razor" %}
@@ -192,37 +192,75 @@ Programmatically select a cell using the [SelectCellAsync](https://help.syncfusi
192192

193193
{% previewsample "https://blazorplayground.syncfusion.com/embed/hNVyZaVTqLCPsIEu?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
194194

195-
## Customize cell selection
195+
## Customize cell selection action
196+
197+
You may customize cell selection behavior in the Gantt Chart using [cellSelecting](https://ej2.syncfusion.com/angular/documentation/api/gantt/events/#cellselecting), [cellSelected](https://ej2.syncfusion.com/angular/documentation/api/gantt/events/#cellselected), [cellDeselecting](https://ej2.syncfusion.com/angular/documentation/api/gantt/events/#celldeselecting), and [cellDeselected](https://ej2.syncfusion.com/angular/documentation/api/gantt/events/#celldeselected) events.
196198

197-
Control cell selection behavior using the [CellSelecting](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.GanttEvents-1.html#Syncfusion_Blazor_Gantt_GanttEvents_1_CellSelecting) and [CellSelected](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Gantt.GanttEvents-1.html#Syncfusion_Blazor_Gantt_GanttEvents_1_CellSelected) events. The `CellSelecting` event triggers before selection, allowing cancellation of specific cell selections based on conditions (e.g., task ID). The `CellSelected` event triggers after selection, providing access to selected cell details.
199+
The following sample demonstrates selection is canceled in the `cellSelecting` event when the **TaskName** is **Perform Soil test**.
198200

199201
{% tabs %}
200202
{% highlight razor tabtitle="Index.razor" %}
201203

202204
@using Syncfusion.Blazor.Gantt
203205
@using Syncfusion.Blazor.Grids
204206

207+
@if (showMessage)
208+
{
209+
<div style="margin-top:10px; font-weight:bold;color:red">@message</div>
210+
}
205211
<SfGantt DataSource="@TaskCollection" Height="450px" Width="700px">
206212
<GanttTaskFields Id="TaskID" Name="TaskName" StartDate="StartDate" EndDate="EndDate" Duration="Duration" Progress="Progress" ParentID="ParentID">
207213
</GanttTaskFields>
208-
<GanttSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Cell"></GanttSelectionSettings>
209-
<GanttEvents CellSelecting="CellSelectingAsync" TValue="TaskData"></GanttEvents>
214+
<GanttSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Cell" Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GanttSelectionSettings>
215+
<GanttEvents TValue="TaskData" CellSelecting="CellSelectingAsync" CellSelected="CellSelectedAsync" CellDeselecting="CellDeselectingAsync" CellDeselected="CellDeselectedAsync">
216+
</GanttEvents>
210217
</SfGantt>
211218

212219
@code {
213-
public async Task CellSelectingAsync(Syncfusion.Blazor.Grids.CellSelectingEventArgs<TaskData> args)
220+
private List<TaskData> TaskCollection { get; set; }
221+
private string message;
222+
private bool showMessage;
223+
224+
protected override void OnInitialized()
214225
{
215-
if (args.Data.TaskID == 2)
226+
TaskCollection = GetTaskCollection();
227+
}
228+
229+
public Task CellSelectedAsync(CellSelectEventArgs<TaskData> args)
230+
{
231+
showMessage = true;
232+
message = $"CellSelected: RowIndex={args.RowIndex}, CellIndex={args.CellIndex}";
233+
return Task.CompletedTask;
234+
}
235+
236+
public Task CellSelectingAsync(CellSelectingEventArgs<TaskData> args)
237+
{
238+
showMessage = true;
239+
message = $"CellSelecting: RowIndex={args.RowIndex}, CellIndex={args.CellIndex}";
240+
241+
if (args.Data?.TaskName == "Perform soil test")
216242
{
217243
args.Cancel = true;
244+
message += " Selection canceled for 'Perform soil test'";
218245
}
246+
247+
return Task.CompletedTask;
219248
}
220249

221-
private List<TaskData> TaskCollection { get; set; }
250+
public Task CellDeselectingAsync(CellDeselectEventArgs<TaskData> args)
251+
{
252+
showMessage = true;
253+
message = $"CellDeselecting: RowIndex={args.RowIndex}, CellIndex={args.CellIndex}";
222254

223-
protected override void OnInitialized()
255+
return Task.CompletedTask;
256+
}
257+
258+
public Task CellDeselectedAsync(CellDeselectEventArgs<TaskData> args)
224259
{
225-
this.TaskCollection = GetTaskCollection();
260+
showMessage = true;
261+
message = $"CellDeselected: RowIndex={args.RowIndex}, CellIndex={args.CellIndex}";
262+
263+
return Task.CompletedTask;
226264
}
227265

228266
public class TaskData
@@ -238,24 +276,24 @@ Control cell selection behavior using the [CellSelecting](https://help.syncfusio
238276

239277
public static List<TaskData> GetTaskCollection()
240278
{
241-
List<TaskData> Tasks = new List<TaskData>()
279+
return new List<TaskData>()
242280
{
243-
new TaskData() { TaskID = 1, TaskName = "Project initiation", StartDate = new DateTime(2022, 04, 05), EndDate = new DateTime(2022, 04, 08), },
281+
new TaskData() { TaskID = 1, TaskName = "Project initiation", StartDate = new DateTime(2022, 04, 05), EndDate = new DateTime(2022, 04, 08) },
244282
new TaskData() { TaskID = 2, TaskName = "Identify Site location", StartDate = new DateTime(2022, 04, 05), Duration = "0", Progress = 30, ParentID = 1 },
245283
new TaskData() { TaskID = 3, TaskName = "Perform soil test", StartDate = new DateTime(2022, 04, 05), Duration = "4", Progress = 40, ParentID = 1 },
246284
new TaskData() { TaskID = 4, TaskName = "Soil test approval", StartDate = new DateTime(2022, 04, 05), Duration = "0", Progress = 30, ParentID = 1 },
247-
new TaskData() { TaskID = 5, TaskName = "Project estimation", StartDate = new DateTime(2022, 04, 06), EndDate = new DateTime(2022, 04, 08), },
285+
new TaskData() { TaskID = 5, TaskName = "Project estimation", StartDate = new DateTime(2022, 04, 06), EndDate = new DateTime(2022, 04, 08) },
248286
new TaskData() { TaskID = 6, TaskName = "Develop floor plan for estimation", StartDate = new DateTime(2022, 04, 06), Duration = "3", Progress = 30, ParentID = 5 },
249287
new TaskData() { TaskID = 7, TaskName = "List materials", StartDate = new DateTime(2022, 04, 06), Duration = "3", Progress = 40, ParentID = 5 },
250288
new TaskData() { TaskID = 8, TaskName = "Estimation approval", StartDate = new DateTime(2022, 04, 06), Duration = "0", Progress = 30, ParentID = 5 }
251289
};
252-
return Tasks;
253290
}
254291
}
292+
255293
{% endhighlight %}
256294
{% endtabs %}
257295

258-
{% previewsample "https://blazorplayground.syncfusion.com/embed/VDBotkrfqVhnDqaK?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
296+
{% previewsample "https://blazorplayground.syncfusion.com/embed/LjLSWZiNfkwAecQJ?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}
259297

260298
> **Note**: Use `CellSelecting` to restrict selections based on task properties. Log selected cell details with `CellSelected` for custom actions. Ensure selections are accessible via keyboard (e.g., <kbd>Shift</kbd> + arrow keys for range selection).
261299

0 commit comments

Comments
 (0)