Skip to content

DataGrid: OnRowFocus returns wrong RowIndex after sorting #596

@fnm4711

Description

@fnm4711

🐛 Bug Report

I'm using 2.4.1 (nuget package)

In OnRowFocus a wrong RowIndex is returned after I reordered the rows (via "sortable=true")

💻 Repro or Code Sample

<FluentDataGrid RowsData="@(tkbms.AsQueryable())" Pagination="@pagination" style="width: 600px;" OnRowFocus="HandleRowFocus" OnCellFocus="HandleCellFocus" TGridItem="DBO_TKBM">
       <PropertyColumn Property="@(t => t.pk.bmnr)" Sortable="true" Title="BMNR" />
       <PropertyColumn Property="@(t => t.attr.bez)" Sortable="true" Title="Bezeichnung"/>
   </FluentDataGrid>
   <FluentPaginator State="@pagination" />

...
private void HandleRowFocus(FluentDataGridRow<DBO_TKBM> r)
{
    int idx = (r.RowIndex ?? 0) - 1;

    logger.LogInformation($"Row focused: {idx}");
    if(idx >= 0 && idx < tkbms.Count)
    {
        DBO_TKBM t = tkbms[idx];
        logger.LogInformation($"  {t.pk.bmnr} - {t.attr.bez}");
    }
}

Notice: List<DBO_TKBM> tkbms = ...

🤔 Expected Behavior

The event (handler) should always return the correct RowId that can be used as an index to the IQueryable that holds the data.

😯 Current Behavior

Before reordering everything is fine. Also together with pagination.
After reordering the returned RowIndex is more or less random.
Regardless if done with or without pagination.

💁 Possible Solution

I did a little research in the source code.
I think the problem occurs when reording. As a side effect it seems to be that the datarows were re-registered but the index later used as the RowIndex is not reset to 0 as done in the initial registration.

🔦 Context

Currently just a POC application. But this bug will make FluentDataGrid totally useless for me.

🌍 Your Environment

Windows10 (x64)
.NET8 (latest preview)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions