Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Refactoring ColumnBase events #2298

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,36 @@
Gets a reference to the enclosing <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1" />.
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.OnRowClickAsync(Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow{`0})">
<summary>
Event callback for when the row is clicked.
</summary>
<param name="row"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.OnRowKeyDownAsync(Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow{`0},Microsoft.AspNetCore.Components.Web.KeyboardEventArgs)">
<summary>
Event callback for when the key is pressed on a row.
</summary>
<param name="row"></param>
<param name="args"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.OnCellClickAsync(Microsoft.FluentUI.AspNetCore.Components.FluentDataGridCell{`0})">
<summary>
Event callback for when the cell is clicked.
</summary>
<param name="cell"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.OnCellKeyDownAsync(Microsoft.FluentUI.AspNetCore.Components.FluentDataGridCell{`0},Microsoft.AspNetCore.Components.Web.KeyboardEventArgs)">
<summary>
Event callback for when the key is pressed on a cell.
</summary>
<param name="cell"></param>
<param name="args"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.CellContent(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder,`0)">
<summary>
Overridden by derived components to provide rendering logic for the column's cells.
Expand Down Expand Up @@ -1558,6 +1588,36 @@
Allows to clear the selection.
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.SelectColumn`1.OnRowClickAsync(Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow{`0})">
<summary>
Select on Unselect an item when the row is clicked.
</summary>
<param name="row"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.SelectColumn`1.OnRowKeyDownAsync(Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow{`0},Microsoft.AspNetCore.Components.Web.KeyboardEventArgs)">
<summary>
Select on Unselect an item when the navigation keys are pressed.
</summary>
<param name="row"></param>
<param name="args"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.SelectColumn`1.OnCellClickAsync(Microsoft.FluentUI.AspNetCore.Components.FluentDataGridCell{`0})">
<summary>
Select on Unselect an item when the cell is clicked.
</summary>
<param name="cell"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.SelectColumn`1.OnCellKeyDownAsync(Microsoft.FluentUI.AspNetCore.Components.FluentDataGridCell{`0},Microsoft.AspNetCore.Components.Web.KeyboardEventArgs)">
<summary>
Select on Unselect an item when the navigation keys are pressed.
</summary>
<param name="cell"></param>
<param name="args"></param>
<returns></returns>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.SelectColumn`1.AddOrRemoveSelectedItemAsync(`0)">
<summary />
</member>
Expand Down Expand Up @@ -1585,6 +1645,9 @@
<member name="M:Microsoft.FluentUI.AspNetCore.Components.SelectColumn`1.OnClickAllAsync(Microsoft.AspNetCore.Components.Web.MouseEventArgs)">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.SelectColumn`1.OnKeyAllAsync(Microsoft.AspNetCore.Components.Web.KeyboardEventArgs)">
<summary />
</member>
<member name="T:Microsoft.FluentUI.AspNetCore.Components.SortedProperty">
<summary>
Holds the name of a property and the direction to sort by.
Expand Down Expand Up @@ -1773,11 +1836,6 @@
A default fragment is used if loading content is not specified.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.SelectColumns">
<summary>
Gets the first (optional) SelectColumn
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.#ctor">
<summary>
Constructs an instance of <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1"/>.
Expand Down Expand Up @@ -5450,6 +5508,9 @@
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentPersona.GetDefaultInitials">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentPersona.GetDefaultInitials(System.String)">
<summary />
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentSelect`1.InlineStyleValue">
<summary />
</member>
Expand Down
90 changes: 74 additions & 16 deletions src/Core/Components/DataGrid/Columns/ColumnBase.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Microsoft.FluentUI.AspNetCore.Components.DataGrid.Infrastructure;

Expand All @@ -11,48 +12,56 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
/// <typeparam name="TGridItem">The type of data represented by each row in the grid.</typeparam>
public abstract partial class ColumnBase<TGridItem>
{
[CascadingParameter] internal InternalGridContext<TGridItem> InternalGridContext { get; set; } = default!;
[CascadingParameter]
internal InternalGridContext<TGridItem> InternalGridContext { get; set; } = default!;

/// <summary>
/// Gets or sets the title text for the column.
/// This is rendered automatically if <see cref="HeaderCellItemTemplate" /> is not used.
/// </summary>
[Parameter] public string? Title { get; set; }
[Parameter]
public string? Title { get; set; }

/// <summary>
/// Gets or sets the an optional CSS class name.
/// If specified, this is included in the class attribute of header and grid cells
/// for this column.
/// </summary>
[Parameter] public string? Class { get; set; }
[Parameter]
public string? Class { get; set; }

/// <summary>
/// Gets or sets an optional CSS style specification.
/// If specified, this is included in the style attribute of header and grid cells
/// for this column.
/// </summary>
[Parameter] public string? Style { get; set; }
[Parameter]
public string? Style { get; set; }

/// <summary>
/// If specified, controls the justification of header and grid cells for this column.
/// </summary>
[Parameter] public Align Align { get; set; }
[Parameter]
public Align Align { get; set; }

/// <summary>
/// If true, generates a title and aria-label attribute for the cell contents
/// </summary>
[Parameter] public bool Tooltip { get; set; } = false;
[Parameter]
public bool Tooltip { get; set; } = false;

/// <summary>
/// Gets or sets the value to be used as the tooltip and aria-label in this column's cells
/// </summary>
[Parameter] public Func<TGridItem, string?>? TooltipText { get; set; }
[Parameter]
public Func<TGridItem, string?>? TooltipText { get; set; }

/// <summary>
/// Gets or sets an optional template for this column's header cell.
/// If not specified, the default header template includes the <see cref="Title" /> along with any applicable sort indicators and options buttons.
/// </summary>
[Parameter] public RenderFragment<ColumnBase<TGridItem>>? HeaderCellItemTemplate { get; set; }
[Parameter]
public RenderFragment<ColumnBase<TGridItem>>? HeaderCellItemTemplate { get; set; }

/// <summary>
/// If specified, indicates that this column has this associated options UI. A button to display this
Expand All @@ -61,7 +70,8 @@ public abstract partial class ColumnBase<TGridItem>
/// If <see cref="HeaderCellItemTemplate" /> is used, it is left up to that template to render any relevant
/// "show options" UI and invoke the grid's <see cref="FluentDataGrid{TGridItem}.ShowColumnOptionsAsync(ColumnBase{TGridItem})" />).
/// </summary>
[Parameter] public RenderFragment? ColumnOptions { get; set; }
[Parameter]
public RenderFragment? ColumnOptions { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the data should be sortable by this column.
Expand All @@ -70,14 +80,16 @@ public abstract partial class ColumnBase<TGridItem>
/// or <see cref="PropertyColumn{TGridItem, TProp}" /> is sortable by default if any<see cref="TemplateColumn{TGridItem}.SortBy" />
/// or <see cref="PropertyColumn{TGridItem, TProp}.SortBy" /> parameter is specified).
/// </summary>
[Parameter] public bool? Sortable { get; set; }
[Parameter]
public bool? Sortable { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the data is currently filtered by this column.
///
/// The default value is false.
/// </summary>
[Parameter] public bool? Filtered { get; set; }
[Parameter]
public bool? Filtered { get; set; }

/// <summary>
/// Gets or sets the sorting rules for a column.
Expand All @@ -88,29 +100,75 @@ public abstract partial class ColumnBase<TGridItem>
/// Gets or sets the initial sort direction.
/// if <see cref="IsDefaultSortColumn"/> is true.
/// </summary>
[Parameter] public SortDirection InitialSortDirection { get; set; } = default;
[Parameter]
public SortDirection InitialSortDirection { get; set; } = default;

/// <summary>
/// Gets or sets a value indicating whether this column should be sorted by default.
/// </summary>
[Parameter] public bool IsDefaultSortColumn { get; set; } = false;
[Parameter]
public bool IsDefaultSortColumn { get; set; } = false;

/// <summary>
/// If specified, virtualized grids will use this template to render cells whose data has not yet been loaded.
/// </summary>
[Parameter] public RenderFragment<PlaceholderContext>? PlaceholderTemplate { get; set; }
[Parameter]
public RenderFragment<PlaceholderContext>? PlaceholderTemplate { get; set; }

/// <summary>
/// Gets or sets the width of the column.
/// Use either this or the <see cref="FluentDataGrid{TGridItem}"/> GridTemplateColumns parameter but not both.
/// Needs to be a valid CSS width value like '100px', '10%' or '0.5fr'.
/// </summary>
[Parameter] public string? Width { get; set; }
[Parameter]
public string? Width { get; set; }

/// <summary>
/// Gets a reference to the enclosing <see cref="FluentDataGrid{TGridItem}" />.
/// </summary>
public FluentDataGrid<TGridItem> Grid => InternalGridContext.Grid;
internal FluentDataGrid<TGridItem> Grid => InternalGridContext.Grid;

/// <summary>
/// Event callback for when the row is clicked.
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
protected internal virtual Task OnRowClickAsync(FluentDataGridRow<TGridItem> row)
{
return Task.CompletedTask;
}

/// <summary>
/// Event callback for when the key is pressed on a row.
/// </summary>
/// <param name="row"></param>
/// <param name="args"></param>
/// <returns></returns>
protected internal virtual Task OnRowKeyDownAsync(FluentDataGridRow<TGridItem> row, KeyboardEventArgs args)
{
return Task.CompletedTask;
}

/// <summary>
/// Event callback for when the cell is clicked.
/// </summary>
/// <param name="cell"></param>
/// <returns></returns>
protected internal virtual Task OnCellClickAsync(FluentDataGridCell<TGridItem> cell)
{
return Task.CompletedTask;
}

/// <summary>
/// Event callback for when the key is pressed on a cell.
/// </summary>
/// <param name="cell"></param>
/// <param name="args"></param>
/// <returns></returns>
protected internal virtual Task OnCellKeyDownAsync(FluentDataGridCell<TGridItem> cell, KeyboardEventArgs args)
{
return Task.CompletedTask;
}

/// <summary>
/// Overridden by derived components to provide rendering logic for the column's cells.
Expand Down
Loading
Loading