Skip to content

Commit

Permalink
Make sure SelectedRow/SelectedRows changes are always notificated to …
Browse files Browse the repository at this point in the history
…DatagridRow by setting them up as parameters. (#3457)

Co-authored-by: Mladen Macanović <[email protected]>
  • Loading branch information
David-Moreira and stsrki authored Feb 16, 2022
1 parent e03b2a1 commit abc6aeb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Source/Extensions/Blazorise.DataGrid/DataGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@
@code {

private RenderFragment paginationFragment => __builder =>
{
<_DataGridPagination TItem="TItem" PaginationContext="@PaginationContext" PaginationTemplates="@PaginationTemplates" OnPaginationItemClick="@(EventCallback.Factory.Create<string>(this, Paginate))" SelectedRow="@SelectedRow" />
};
{
<_DataGridPagination TItem="TItem" PaginationContext="@PaginationContext" PaginationTemplates="@PaginationTemplates" OnPaginationItemClick="@(EventCallback.Factory.Create<string>(this, Paginate))" SelectedRow="@SelectedRow" />
};

protected RenderFragment<TItem> rowFragment => item => __builder =>
{
Expand All @@ -226,7 +226,7 @@
}
else
{
<_DataGridRow @key="@item" TItem="TItem" Item="@item" />
<_DataGridRow @key="@item" TItem="TItem" Item="@item" SelectedRows="SelectedRows" SelectedRow="SelectedRow" />
if ( DetailRowTemplate != null && ( GetRowInfo( item )?.HasDetailRow ?? false ) )
{
<_DataGridDetailRow TItem="TItem" Item="@item" Columns="@Columns">
Expand Down
16 changes: 16 additions & 0 deletions Source/Extensions/Blazorise.DataGrid/_DataGridRow.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public override Task SetParametersAsync( ParameterView parameters )
case nameof( ParentDataGrid ):
ParentDataGrid = (DataGrid<TItem>)parameter.Value;
break;
case nameof( SelectedRow ):
SelectedRow = (TItem)parameter.Value;
break;
case nameof( SelectedRows ):
SelectedRows = (List<TItem>)parameter.Value;
break;
default:
throw new ArgumentException( $"Unknown parameter: {parameter.Name}" );
}
Expand Down Expand Up @@ -248,6 +254,16 @@ protected string GetStyle( DataGridRowStyling styling, DataGridRowStyling select

[Parameter] public RenderFragment ChildContent { get; set; }

/// <summary>
/// Gets or sets currently selected row.
/// </summary>
[Parameter] public TItem SelectedRow { get; set; }

/// <summary>
/// Gets or sets currently selected rows.
/// </summary>
[Parameter] public List<TItem> SelectedRows { get; set; }

#endregion
}
}

0 comments on commit abc6aeb

Please sign in to comment.