MudDataGrid: Fix virtualized indexes (#10179)#10218
MudDataGrid: Fix virtualized indexes (#10179)#10218ScarletKuro merged 11 commits intoMudBlazor:devfrom Ptipoi-jf:fix/datagrid-virtualized-indexes
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #10218 +/- ##
==========================================
- Coverage 91.52% 91.50% -0.02%
==========================================
Files 413 414 +1
Lines 12979 12979
Branches 2447 2450 +3
==========================================
- Hits 11879 11877 -2
Misses 557 557
- Partials 543 545 +2 ☔ View full report in Codecov by Sentry. |
|
before, virtualize call look like after fix : |
|
@KapustinVadim1991, could you review this to ensure it's a good fix and that it doesn't break existing virtualization functionality in the datagrid? I'm asking because you were the one who mainly implemented this feature. |
@Ptipoi-jf Good afternoon, this block of code covered the following case: we have a list with TotalItems = 10, and we request through the virtualization component with StartIndex = 8, Count = 2. At this point, everything works correctly, and we receive the required records. Then, an external filter changes (I’m not sure about internal DataGrid filters), and I call ReloadServerData, which returns TotalItems = 5. However, the StartIndex in the DataGrid has not changed, so we will receive 0 records. The main question is how to reset StartIndex to 0 and request a new collection; otherwise, the DataGrid will remain in this state. This is an edge case, but it’s crucial for the project I’m developing, as all our filters are external. If you plan to remove this part of the code, there should be a method allowing the list request indices to reset (ReloadServerData(rbool resetIndices) or something like that). |
|
@KapustinVadim1991 Good afternoon, thanks to review Understood, but this is a weird fix i guess. i'll create a new component in the viewer project to check that. => this method already exist and named <Virtualize ... @ref="virtualizeComponent">
...
</Virtualize>
...
private Virtualize<FetchData>? virtualizeComponent;
protected override void OnInitialized()
{
WeatherForecastSource.ForecastUpdated += async () =>
{
await InvokeAsync(async () =>
{
await virtualizeComponent?.RefreshDataAsync();
StateHasChanged();
});
});
}Btw, if i'm removing this bloc, this is now a breaking change, so i can restore this part then PR an other fix-breaking. What did you think about ? EDIT : /// <summary>
/// Refreshes the data in the Virtualize component asynchronously.
/// </summary>
public async Task RefreshDataAsync()
{
if (_virtualizeContainerReference != null)
{
await _virtualizeContainerReference.RefreshDataAsync();
}
} |
|
@Ptipoi-jf I’m completely in favor of keeping this part of the code, as it ideally doesn’t break virtualization behavior—it simply requests records from the 0 index if, for some reason, the TotalItemsCount doesn’t match reality, as it shouldn’t be less than StartIndex + Count, if I’m not mistaken. The filter case is as follows: on my page, I have a DataGrid, but the client requests a unified search field for all data located outside the DataGrid. So, I create a DataGrid, assign it a function for data retrieval, and also need to reload the data in the DataGrid since the filter has changed, so I call the DataGrid.ReloadServerData method. Perhaps RefreshDataAsync uses the same indexes as before—I can’t say for sure. If it resets StartIndex, it could be a potentially elegant solution, but I guess it just call the provided function with the same indices. |
Do I understand correctly that if DataGrid had an event that tells the filters were updated inside DataGrid, then this code part wouldn't be needed? If so, then in that case we probably would want to make that feature first before continuing this PR if there is no other ways to make things more or less compatible if there is no other ways for you to do your edge case. |
Implementing the event won’t change the situation, as the event will still call InvokeServerLoadFunc, which will reload the data from the server with the same StartIndex and Count. I reviewed the code, and if my calculations are correct, internal filters will also trigger the same method without modifying StartIndex. Sorry, I haven’t tried reproducing it, as it would require removing the code section that you plan to delete, but here are the test parameters for checking DataGrid functionality after the changes (removing that code block with the check): create a DataGrid (Virtualize + VirtualizeServerData) with 100 items, scroll to the end of the list, and change the filter so that only 10 items (approximately) match the filter criteria. Expected result: 10 records, not 0. |
that break how virtualize component work because you returning element outside requested range. my first fix here was to take Let me test with the search field and then we can discuss about it |
…zeServerDataLoadingTestWithSearch.razor`
|
@KapustinVadim1991 This is an other bug, the native virtualize component is working fine. I push if you wanna check yourself until i search the main reason ? new viewer file : |
|
The When you type slowly in the search field it works (one char by one), but when you type or remove multiple chars it display empty even if search field is empty. i'm searching a fix. |
(Virtualize + VirtualizeServerData) with 100 items, scroll to the end of the list, and change the filter so that only 10 items (approximately) match the filter criteria. Expected result: 10 records, not 0. Note : The footer has not been fixed, it will show incorrect result (ie 0)
|
i've got a partial fix => empty result can appear in the footer because |
|
Good morning, I checked the DataGridVirtualizeServerDataLoadingTestWithSearch in your branch and see that everything is working perfectly, and the bug with rapid input is also fixed. I also decided to check the dev branch with and without the Thank you for the PR 😊 @ScarletKuro I have no more questions |
hmm, this is a bit strange, i was able to reproduce in my branch with DataGridVirtualizeServerDataLoadingTestWithSearch before the fix did i need to add |
I meant that the bug I mentioned wasn’t reproduced in 100% of cases, while the side bug with rapid input was reproducible in the dev branch but not in your branch 😊
I didn’t quite understand the part about EmptyContent, but NoRecordContent is used in my project across all DataGrids with VirtualizeServerData, and it works correctly. |
|
I need to check in my branch if EmptyContent is correctly displayed with virtualization enable. |
|
What is the status? Is this ready to be merged? |
|
@ScarletKuro & @KapustinVadim1991 can you check my last commit then it's ready to merge. The grid must show now Edit : can you explain me why my new component |
|
I will try to re-review it on weekends. |
|
|
I actually don't know how to reliably test it. bUnit sets the viewport to 1,000,000,000 for the Will just merge and hope there won't be complains. |
|
is this PR will be merge as fix for V7 too ? Rememeber - there is another side bug when using virtualization :
|
|
This caused regression #10343
I would prefer not for now, I want to get feedbacks from v8 first, and as you can see for good reason. Also, these changes have conflict with v7 if you try to port it, so you would need to create a new PR against v7 branch. |
|
As for now I created this PR #10361 which will be on hold |
…ession come from MudBlazor#10218, revert from MudBlazor#10361 can be cancelled
Co-authored-by: Ptipoi-fj <[email protected]> Co-authored-by: Artyom M. <[email protected]>



Description
rowIndexcannot be computed like that when using Virtualize component.The base framework has responsability about that bug because it don't provide index related information.
To bypass that missing index, we can used an internediate object to store this index (i name it
IndexBag)fixes #10179.
note : removing code bloc at line 1776, this is the responsability to the virtualize component to define what is the item to display. When virtualize component ask to items [12,13,14,15,16] we must not return [0,1,2,3,4] even if the page size is not complete
How Has This Been Tested?
Failing tests are outside this PR scope, all running for DataGrid
Creating component
DataGridVirtualizeServerDataLoadingTestLargeDataSet.razorinMudBlazor.UnitTests.Viewerproject and testing with other DataGrid components inMudBlazor.UnitTests.Vieweri don't have created unit test - i don't know how to create it to check the fix
Type of Changes
Checklist
dev).