Radzen DataGrid - filtering with streaming data

Hi,

I use the lovely RadzenDataGrid with streaming data. For example i have IEnumarble which is assigned to the Data property of the grid, and on new MarketPrice i replace the corresponding MarketPrice item in the collection. This works great for showing market data (or what i call streaming data). The grid shows the new price value for the given row as expected.

The issue comes when i enable the grid filtering with AllowFiltering="true" FilterMode="FilterMode.SimpleWithMenu". I type someting in the filter and for a moment the filter works fine, i.e. the grid rows a filtered according to the filter value, but when a new MarketPrice is received the filter loses the value and the grid shows all rows again.

I am probably not approaching this correctly and would like to know if there is a way to address this scenario.

Many thanks,

Alex

Hi @a.naydenov,

Not sure how your data are refreshed however here is an example with dynamic data update and filtering:


dynamic-data

Here is the complete code:

@page "/datagrid-dynamic"
@using System.Linq.Dynamic.Core

<RadzenText TextStyle="TextStyle.H3" TagName="TagName.H1" Class="my-4">
    DataGrid <strong>dynamic</strong> data support
</RadzenText>
<RadzenText TextStyle="TextStyle.Body1" Class="my-4">
    Sometimes your data comes from external API and you don't have a C# model for it. This demo shows how to implement such a scenario.
</RadzenText>

<RadzenExample Name="DataGrid" Source="DataGridDynamicData" Heading="false">
    <RadzenDataGrid @ref=grid Count=@count Data=@data LoadData="@LoadData" TItem="MyObject"
                         AllowFiltering="true" FilterMode="FilterMode.SimpleWithMenu" AllowPaging="true" AllowSorting="true">
            <Columns>
                <RadzenDataGridColumn TItem="MyObject" Property="Id" Title="Id" />
                <RadzenDataGridColumn TItem="MyObject" Property="Date" Title="Date" />
            </Columns>
        </RadzenDataGrid>
</RadzenExample>
@code {
    public IQueryable<MyObject> data;
    public int count;

    RadzenDataGrid<MyObject> grid;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        var timer = new System.Threading.Timer(async (object? stateInfo) =>
        {
            await InvokeAsync(grid.Reload);
        }, new System.Threading.AutoResetEvent(false), 1000, 1000);
    }

    async Task LoadData(LoadDataArgs args)
    {
        data = Enumerable.Range(0, 10).Select(i => new MyObject() { Id = i, Date = $"{DateTime.Now}" }).AsQueryable();

        if (!string.IsNullOrEmpty(args.Filter))
        {
            data = data.Where(args.Filter);
        }

        count = data.Count();
    }

    public class MyObject
    {
        public int Id { get; set; }
        public string Date { get; set; }
    }
}
1 Like