请求更改时 Blazor Virtualize 更新

标签 blazor

我有一个组件可以显示数据库中多达 200000 名运动员。
它工作得很好,但是当我添加一个带有国家列表的选择时,我可以看到结果计数已更新,但 Virtualize 组件在我滚动之前不会更新?

@page "/persons"
@inject HttpClient Http


<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <h1>@($"{totalindividu:### ### ##0}") athletes linked</h1>
        </div>
    </div>
    <div class="row">
        <div class="col-4">
            <select class="form-control" @onchange="ChangePays">
                <option value="-1" selected>Pas de sélection sur le pays</option>
                @if (pays != null)
                {
                    @foreach (var p in pays)
                    {
                    <option value="@p.aatpays_id">@p.aaipays_nom</option>
                    }
                }
            </select>
        </div>
        <div class="col-4">&nbsp;</div>
        <div class="col-4"><p>@selpays</p></div>
    </div>
    <div class="row">
        <div class="col-12">
            <table class="table">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Code</th>
                        <th>Nom long</th>
                        <th>Pays</th>
                        <th>Discipline</th>
                        <th>Date de naissance</th>
                    </tr>
                </thead>
                <tbody>
                    <Virtualize Context="individu" ItemsProvider="@LoadIndividus">
                        <ItemContent>
                            <tr>
                                <td style="width: 100px">@individu.aatindividu_id</td>
                                <td style="width: 100px">@individu.aalindividu_code</td>
                                <td>@individu.aaiindividu_nomLong</td>
                                <td style="width: 200px">@individu.aaipays_nom</td>
                                <td style="width: 200px">@individu.aaidiscipline_nom</td>
                                <td style="width: 100px">@individu.aatindividu_dateNaissance</td>
                            </tr>
                        </ItemContent>
                        <Placeholder>
                            <tr>
                                <td style="width: 100px">Loading...</td>
                                <td style="width: 100px">Loading...</td>
                                <td>Loading...</td>
                                <td style="width: 200px">Loading...</td>
                                <td style="width: 200px">Loading...</td>
                                <td style="width: 100px">Loading...</td>
                            </tr>
                        </Placeholder>
                    </Virtualize>
                </tbody>
            </table>
        </div>
    </div>
</div>

@code {
    private int totalindividu = 0;
    private string selpays = "-1";
    private BdsPays[] pays = null;
    private BdsIndividu[] individus = null;

    protected override async Task OnInitializedAsync()
    {
        pays = await Http.GetFromJsonAsync<BdsPays[]>("api/BdsAa/pays/1");
        //individus = await LoadIndividus(0, 50);
    }

    private async Task<BdsIndividu[]> LoadIndividus(int start, int count)
    {
        totalindividu = await Http.GetFromJsonAsync<int>($"api/BdsAa/individusinoutcount/1/33/{selpays}");
        individus = await Http.GetFromJsonAsync<BdsIndividu[]>($"api/BdsAa/individusinout/1/33/{start}/{count}/{selpays}");
        return individus;
    }

    private async ValueTask<ItemsProviderResult<BdsIndividu>> LoadIndividus(ItemsProviderRequest request)
    {
        individus = await LoadIndividus(request.StartIndex, request.Count);
        StateHasChanged();
        return new ItemsProviderResult<BdsIndividu>(individus, totalindividu);
    }

    private async Task ChangePays(ChangeEventArgs e)
    {
        selpays = e.Value.ToString();
        individus = null;
        StateHasChanged();
    }
}
当我的过滤器更改时强制更新表格的任何想法?

最佳答案

您应该可以调用RefreshDataAsync()如下。
来自 GitHub添加此功能的问题

For the more general case where the developer uses ItemsProvider, we should add a new public async Task RefreshDataAsync method on Virtualize. Developers can call this if they have reason to think the underlying data source output may have changed, for example when a user clicks a "Refresh" button. This would just do the same thing that happens when the user scrolls into a new set of data.

关于请求更改时 Blazor Virtualize 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65449283/

相关文章:

forms - Blazor EditForm 从列表绑定(bind)

visual-studio - .razor 文件中的 Blazor Intellisense 在发布后停止工作

asp.net-core - 在 ASP.NET Core 中使用 ValidationMessage 时,我可以添加或更改默认的 CSS 类吗?

pdf - 从字节数组在 Blazor 页面中显示 PDF 的问题

c# - 为什么 Blazor 不会路由到 Razor 库中的组件?

.net-core - Blazor Server 将多个组件中的模型绑定(bind)到单个 EditForm

c# - 如何在现有 blazor 项目上启用 PWA 功能

c# - 当用户未在 Blazor 中获得授权时,我想显示带有路由的多个页面

c# - Blazor 服务器构建错误 - 新的 Web 应用程序导致构建错误

c# - 如何让 System.Diagnostics 在 Ubuntu Linux 上的 Blazor 应用程序中工作?