Skip to content

Commit 2ff71ca

Browse files
Grid_RowKeySelector
Add the ability to specify a RowKeySelector for a Grid to override the default GetHashCode for Row Keys in the Grid
1 parent 2896fa6 commit 2ff71ca

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

blazorbootstrap/Components/Grid/Grid.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
{
148148
var rowClass = RowClass?.Invoke(item) ?? "";
149149
var detailViewRowId = IdUtility.GetNextId();
150-
<tr @key="item?.GetHashCode()" class="@rowClass" @onclick="args => RowClick(item, args)" @ondblclick="args => RowDoubleClick(item, args)" role="@(AllowRowClick ? "button" : "")">
150+
<tr @key="RowKeySelector?.Invoke(item) ?? item?.GetHashCode()" class="@rowClass" @onclick="args => RowClick(item, args)" @ondblclick="args => RowDoubleClick(item, args)" role="@(AllowRowClick ? "button" : "")">
151151
@if (AllowDetailView)
152152
{
153153
<td class="text-center">

blazorbootstrap/Components/Grid/Grid.razor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,14 @@ private void SetFilters(IEnumerable<FilterItem> filterItems)
995995
[Parameter]
996996
public Func<TItem, string>? RowClass { get; set; }
997997

998+
/// <summary>
999+
/// Gets or sets the row key selector.
1000+
/// usage ex.
1001+
/// RowKeySelector="context => context.UserId"
1002+
/// </summary>
1003+
[Parameter]
1004+
public Func<TItem, object>? RowKeySelector { get; set; }
1005+
9981006
/// <summary>
9991007
/// Gets or sets the selected items.
10001008
/// </summary>

0 commit comments

Comments
 (0)