Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add OnCellClick
  • Loading branch information
dvoituron committed Jun 24, 2024
commit 217a4019dd563bca8c62f68316955c45f2ce00d5
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,11 @@
Gets or sets whether the [All] checkbox is disabled (not clickable).
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.SelectColumn`1.SelectFromEntireRow">
<summary>
Gets or sets whether the selection of rows is restricted to the SelectColumn (false) or if the whole row can be clicked to toggled the selection (true).
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.SelectColumn`1.SelectAllTemplate">
<summary>
Gets or sets the template for the [All] checkbox column template.
Expand Down Expand Up @@ -1720,6 +1725,11 @@
Gets or sets a callback when a row is focused.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.OnCellClick">
<summary>
Gets or sets a callback when a cell is clicked.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.OnRowClick">
<summary>
Gets or sets a callback when a row is clicked.
Expand Down Expand Up @@ -1855,6 +1865,9 @@
Gets or sets the owning <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1"/> component
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridCell`1.HandleOnCellClickAsync">
<summary />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow`1.Item">
<summary>
Gets or sets the reference to the item that holds this row's values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@* Sample using SelectedItems *@
<div>Using SelectedItems</div>

<FluentDataGrid Items="@People" ShowHover="true" TGridItem="Person">
<FluentDataGrid Items="@People" ShowHover="true" TGridItem="Person" OnRowClick="@(e => Console.WriteLine(e.RowIndex))" OnCellClick="@(e => Console.WriteLine(e.GridColumn))">
<SelectColumn TGridItem="Person"
SelectMode="@Mode"
@bind-SelectedItems="@SelectedItems" />
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Components/DataGrid/Columns/SelectColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public SelectColumn()
[Parameter]
public bool SelectAllDisabled { get; set; } = false;

/// <summary>
/// Gets or sets whether the selection of rows is restricted to the SelectColumn (false) or if the whole row can be clicked to toggled the selection (true).
/// </summary>
[Parameter]
public bool SelectFromEntireRow { get; set; } = true;

/// <summary>
/// Gets or sets the template for the [All] checkbox column template.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Components/DataGrid/FluentDataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ public partial class FluentDataGrid<TGridItem> : FluentComponentBase, IHandleEve
[Parameter]
public EventCallback<FluentDataGridCell<TGridItem>> OnCellFocus { get; set; }

/// <summary>
/// Gets or sets a callback when a cell is clicked.
/// </summary>
[Parameter]
public EventCallback<FluentDataGridCell<TGridItem>> OnCellClick { get; set; }

/// <summary>
/// Gets or sets a callback when a row is clicked.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/DataGrid/FluentDataGridCell.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
grid-column=@GridColumn
class="@Class"
style="@StyleValue"
@onclick="@HandleOnCellClickAsync"
@attributes="AdditionalAttributes">
@ChildContent
</fluent-data-grid-cell>
22 changes: 21 additions & 1 deletion src/Core/Components/DataGrid/FluentDataGridCell.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public partial class FluentDataGridCell<TGridItem> : FluentComponentBase
/// Gets or sets the owning <see cref="FluentDataGridRow{TItem}"/> component.
/// </summary>
[CascadingParameter(Name = "OwningRow")]
public FluentDataGridRow<TGridItem> Owner { get; set; } = default!;
internal FluentDataGridRow<TGridItem> Owner { get; set; } = default!;

/// <summary>
/// Gets or sets the owning <see cref="FluentDataGrid{TItem}"/> component
Expand All @@ -59,6 +59,26 @@ protected override void OnInitialized()
Owner.Register(this);
}

/// <summary />
private async Task HandleOnCellClickAsync()
{
if (GridContext.Grid.OnCellClick.HasDelegate)
{
await GridContext.Grid.OnCellClick.InvokeAsync(this);
}

//if (CellType == DataGridCellType.Default && Owner.Owner.Grid.SelectColumns.Any(selColumn => selColumn.RestrictToCheckbox))
//{
// foreach (var selColumn in Owner.Owner.Grid.SelectColumns)
// {
// if (selColumn != null && selColumn.RestrictToCheckbox is true && Owner.Owner.Grid.Columns.IndexOf(selColumn) == GridColumn - 1)
// {
// await selColumn.AddOrRemoveSelectedItemAsync(Item);
// }
// }
//}
}

public void Dispose() => Owner.Unregister(this);

}
2 changes: 1 addition & 1 deletion src/Core/Components/DataGrid/FluentDataGridRow.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public partial class FluentDataGridRow<TGridItem> : FluentComponentBase, IHandle
/// Gets or sets the owning <see cref="FluentDataGrid{TItem}"/> component
/// </summary>
[CascadingParameter]
private InternalGridContext<TGridItem> Owner { get; set; } = default!;
internal InternalGridContext<TGridItem> Owner { get; set; } = default!;

protected string? ClassValue => new CssBuilder(Class)
.AddClass("hover", when: Owner.Grid.ShowHover)
Expand Down