Skip to content
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
@@ -1,14 +1,15 @@
<Grid TItem="Employee1"
Class="table table-hover table-bordered table-striped"
DataProvider="EmployeesDataProvider"
AllowFiltering="true"
AllowPaging="true"
PageSize="5"
AllowSorting="true"
AllowSelection="true"
SelectionMode="GridSelectionMode.Multiple"
Class="table table-hover table-bordered table-striped"
DataProvider="EmployeesDataProvider"
PageSize="5"
Responsive="true"
RowKeySelector="(emp) => emp.Id"
SelectedItemsChanged="OnSelectedItemsChanged"
Responsive="true">
SelectionMode="GridSelectionMode.Multiple">

<GridColumns>
<GridColumn TItem="Employee1" HeaderText="Id" PropertyName="Id" SortKeySelector="item => item.Id">
Expand Down
2 changes: 1 addition & 1 deletion blazorbootstrap/Components/Grid/Grid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
{
var rowClass = RowClass?.Invoke(item) ?? "";
var detailViewRowId = IdUtility.GetNextId();
<tr @key="item?.GetHashCode()" class="@rowClass" @onclick="args => RowClick(item, args)" @ondblclick="args => RowDoubleClick(item, args)" role="@(AllowRowClick ? "button" : "")">
<tr @key="RowKeySelector?.Invoke(item) ?? item?.GetHashCode()" class="@rowClass" @onclick="args => RowClick(item, args)" @ondblclick="args => RowDoubleClick(item, args)" role="@(AllowRowClick ? "button" : "")">
@if (AllowDetailView)
{
<td class="text-center">
Expand Down
12 changes: 12 additions & 0 deletions blazorbootstrap/Components/Grid/Grid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,18 @@ private void SetFilters(IEnumerable<FilterItem> filterItems)
[Parameter]
public Func<TItem, string>? RowClass { get; set; }

/// <summary>
/// Gets or sets the function used to extract a unique key from a row item.
/// </summary>
/// <remarks>
/// The key returned by the function is used to uniquely identify each row in the data set. This
/// is typically required for operations such as tracking changes or rendering rows efficiently.
/// If not set, the item hash code will be used as the key.
/// Example usage: `RowKeySelector="(employee) => employee.Id"`.
/// </remarks>
[Parameter]
public Func<TItem, object>? RowKeySelector { get; set; }

/// <summary>
/// Gets or sets the selected items.
/// </summary>
Expand Down
Loading