DataGrid reload on any click event

Hello and sorry if this has been asked before.

I am using the DataGrid as an event log viewer and also have Radzen DropDowns, DatePicker to filter events on.

If I select anything in the drop downs or dates, the grid reloads itself. None of those events changes anything in the GUI or database. Is there any way of stopping the grid from reloading and only reload when the bound data object is changed? Thanks.

Hi @Odavis,

If the grid data are retrieved on OnInitialized or OnInitializedAsync nothing will be able to reload them except explicit call.

Hi and thank you for the response.

I am not seeing that. Each line of data is being formatted through "GetMessageSpan " and in the format function I have a debug statement that writes to the immediate window and every time I select/deselect an item in one of the drop downs the entire grid view is scrolled in the immediate window. All drop downs are in a separate div from the DataGrid that is in it's own div.

The GetMessageSpan below removes embedded formatting char's and colors lines based on event type. "StateHasChanged" is not called anywhere except in the initial function "OnAfterRenderAsync".

The reloading is not being called from any of the code from what I can see. I traced it to the rendering tree code in ASP .net. We are using the latest 5.0.1 of entity framework core and asp net core. Thanks.

EDIT: Actually, clicking anywhere on the grid also triggers the @((MarkupString)GetMessageSpan(logs)) code.

                        <RadzenGridColumn Width="75px" TItem="Logs" Property="logs.Timestamp" Title="Time Stamp" TextAlign="TextAlign.Left">
                            <HeaderTemplate><span style='color:black; font-weight:normal; font-size:12px'>Time Stamp</span></HeaderTemplate>
                            <Template Context="logs">
                                <span style="color:black; font-weight:normal; font-size:12px">@logs.Timestamp</span>
                            </Template>
                        </RadzenGridColumn>
                        <RadzenGridColumn Width="60px" TItem="Logs" Visible="@ShowIPColumn" Property="@IPAddress" Title="IP Adress" TextAlign="TextAlign.Left">
                            <HeaderTemplate><span style='color:black; font-weight:normal; font-size:12px'>IP Adress</span></HeaderTemplate>
                            <Template Context="logs">
                                <span style="color:black; font-weight:normal; font-size:12px">@IPAddress</span>
                            </Template>
                        </RadzenGridColumn>
                        <RadzenGridColumn Width="600px" TItem="Logs" Property="logs.Message" Title="Message" TextAlign="TextAlign.Left">
                            <HeaderTemplate><span style='color:black; font-weight:normal; font-size:12px'>Message</span></HeaderTemplate>
                            <Template Context="logs">
                                <RadzenImage Path=@GetIconPath(logs) Style="width:12px; height:12px" />
                                @((MarkupString)GetMessageSpan(logs))
                            </Template>
                        </RadzenGridColumn>



    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            GetLogDB(); //<-- This loads the database

            evLogLevels = GetDropDownStrings("Level");
            evSourceContext = GetDropDownStrings("SourceContext");
            evNode = GetDropDownStrings("Node");
 
            StateHasChanged(); //<-- Needed or nothing gets displayed.
        }
    }

How is the Data property set? If it is set to an expression it will cause the DataGrid to rebind on every StateHasChanged() call (because it will set the Data property again).

Hi and thank you for the response.

Yes exactly, but the StateHasChanged() is not being called except on the initial loading of the grid or an expected change. The Data is being used to hold the data of the grid in a variable "evLog" and that is updated for filtering.

Clicking and selecting a drop down item or just clicking on the grid itself is causing the @((MarkupString)GetMessageSpan(logs)) to be called.

Is there a different way to use the grid then this? Thanks for any help.

I can't tell without seeing the complete declaration. Also you can pull the source code from our github repo and trace what is causing the rerendering of the DataGrid.

Here is the complete declaration.

I will try and debug later if possible. This is part of a much larger project and I may not be able to add the github code to run with.

Notes: Logs type is an entity class. evLog is a Entity MySql DB made up of class Logs.
Up top of page

@inject logContext logdb;

Insidee @code block

IEnumerable<Logs> evLog;
evLog = (some Linq code).Take(MaxRecs).ToList();

Blazor html:

        <div id="Events">
            <RadzenCard Style="background-color:linen; padding:5px; width:100%; height:600px">
                <RadzenGrid Data="@evLog" TItem="Logs" @ref="evGrid" RowRender="@RowRender" CellRender="@CellRender" AllowFiltering="false" AllowPaging="false" AllowSorting="false" Style="line-height: 14px; width:100%; height: 585px; margin-right:5px;">
                    <Template Context="logItem">
                        @*Expanded grid*@
                        <RadzenGrid Data="@GetLogItem(logItem)" TItem="Logs" CellRender="@ItemCellRender" AllowPaging="false" AllowSorting="false" AllowFiltering="false">
                            <Columns>
                                <RadzenGridColumn Width="600px" TItem="Logs" Property="log.Message">
                                    <Template Context="logMessage">
                                        @((MarkupString)GetExpandText(logMessage, true))
                                    </Template>
                                </RadzenGridColumn>
                            </Columns>
                        </RadzenGrid>
                    </Template>
                    <Columns>
                        @*Main Grid View*@
                        <RadzenGridColumn Width="75px" TItem="Logs" Property="logs.Timestamp" Title="Time Stamp" TextAlign="TextAlign.Left">
                            <HeaderTemplate><span style='color:black; font-weight:normal; font-size:12px'>Time Stamp</span></HeaderTemplate>
                            <Template Context="logs">
                                <span style="color:black; font-weight:normal; font-size:12px">@logs.Timestamp</span>
                            </Template>
                        </RadzenGridColumn>
                        <RadzenGridColumn Width="60px" TItem="Logs" Visible="@ShowIPColumn" Property="@IPAddress" Title="IP Adress" TextAlign="TextAlign.Left">
                            <HeaderTemplate><span style='color:black; font-weight:normal; font-size:12px'>IP Adress</span></HeaderTemplate>
                            <Template Context="logs">
                                <span style="color:black; font-weight:normal; font-size:12px">@IPAddress</span>
                            </Template>
                        </RadzenGridColumn>
                        <RadzenGridColumn Width="600px" TItem="Logs" Property="logs.Message" Title="Message" TextAlign="TextAlign.Left">
                            <HeaderTemplate><span style='color:black; font-weight:normal; font-size:12px'>Message</span></HeaderTemplate>
                            <Template Context="logs">
                                <RadzenImage Path=@GetIconPath(logs) Style="width:12px; height:12px" />
                                @((MarkupString)GetMessageSpan(logs))
                            </Template>
                        </RadzenGridColumn>
                    </Columns>
                </RadzenGrid>
            </RadzenCard>
        </div>

This code looks correct and I am not sure what could be causing the grid to render again. The only suggestion I could give is to add a ProjectReference to the Radzen.Blazor project file and debug it to see what triggers the update. You can get it from here: https://github.com/radzenhq/radzen-blazor/tree/master/Radzen.Blazor

Thank you. I will try and see what's going on and add that reference.

For what ever reason the Radzen.Blazor project would not add as a reference. There 7 other projects I have all added as references but your would not add only as a dll. So I can't debug to the level you are asking. Sorry.

Any other ideas? Thanks.

If you have a subscription you can send us your application to info@radzen.com and we will troubleshoot. Other than that debugging is the only option.