Radzen DataGrid not updating with SignalR WebSocket data #952

Closed
opened 2026-01-29 17:46:50 +00:00 by claunia · 3 comments
Owner

Originally created by @kElaadwy on GitHub (Aug 9, 2023).

Version: [4.13.4]

Description:

I've encountered a bug when using the Radzen Blazor DataGrid in combination with SignalR WebSocket data. The issue is that the DataGrid doesn't update as expected when new data is received through the SignalR WebSocket connection. This issue is not present when using regular HTML tables to display the same data.

Originally created by @kElaadwy on GitHub (Aug 9, 2023). ### Version: [4.13.4] ### Description: I've encountered a bug when using the Radzen Blazor DataGrid in combination with SignalR WebSocket data. The issue is that the DataGrid doesn't update as expected when new data is received through the SignalR WebSocket connection. This issue is not present when using regular HTML tables to display the same data.
Author
Owner

@enchev commented on GitHub (Aug 9, 2023):

The DataGrid doesn’t know anything about SignalR - you as developer should reload whatever data you need and assign it to Data.

@enchev commented on GitHub (Aug 9, 2023): The DataGrid doesn’t know anything about SignalR - you as developer should reload whatever data you need and assign it to Data.
Author
Owner

@kElaadwy commented on GitHub (Aug 9, 2023):

The Datagrid is showing List<Invoice> invoices .. data coming from SignalR is added to invoices, and StateHasChanged() is called, here is an example :

    hubConnection.On<Invoice>("PrintedInvoice", (invoice) =>
    {
        invoices.Add(invoice);
        StateHasChanged();
    });

As I said, the same logic worked just fine with regular html table

                <table class="table">
                    <thead>
                        <tr>
                            <th>Total price</th>
                            <th>Count</th>
                            <th>Time</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var invoice in invoices)
                        {
                            <tr>
                                <td>@invoice.Total</td>
                                <td>@invoice.NoOfItems</td>
                                <td>@invoice.CreatedOn</td>
                                <td>
                                    <button class="btn btn-link" @onclick="() => IconClicked(invoice)">
                                        <i class="fa-solid fa-qrcode"></i>
                                    </button>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
@kElaadwy commented on GitHub (Aug 9, 2023): The Datagrid is showing `List<Invoice> invoices` .. data coming from SignalR is added to `invoices`, and `StateHasChanged()` is called, here is an example : hubConnection.On<Invoice>("PrintedInvoice", (invoice) => { invoices.Add(invoice); StateHasChanged(); }); As I said, the same logic worked just fine with regular html table <table class="table"> <thead> <tr> <th>Total price</th> <th>Count</th> <th>Time</th> <th>Actions</th> </tr> </thead> <tbody> @foreach (var invoice in invoices) { <tr> <td>@invoice.Total</td> <td>@invoice.NoOfItems</td> <td>@invoice.CreatedOn</td> <td> <button class="btn btn-link" @onclick="() => IconClicked(invoice)"> <i class="fa-solid fa-qrcode"></i> </button> </td> </tr> } </tbody> </table>
Author
Owner

@akorchev commented on GitHub (Aug 9, 2023):

You either need to use ObservableCollection or invoke the Reload method of RadzenDataGrid after adding a new item.

@akorchev commented on GitHub (Aug 9, 2023): You either need to use ObservableCollection or invoke the Reload method of RadzenDataGrid after adding a new item.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#952