Filtered grid row count

Is there a quick way to get the row count as filtered? Like if I wanted to show the filtered count instead of total count in the footer as in this sample.

https://blazor.radzen.com/datagrid-footer-totals

TIA,
Josh

In the same example if you change:

<RadzenGridColumn Width="200px" TItem="Order" Property="OrderID" Title="Order ID">
  <FooterTemplate>
      Total orders: <b>@orders.Count()</b>
  </FooterTemplate>
</RadzenGridColumn>

to

<RadzenGridColumn Width="200px" TItem="Order" Property="OrderID" Title="Order ID">
   <FooterTemplate>
      Total orders: <b>@ordersGrid.View.Count()</b>
   </FooterTemplate>
</RadzenGridColumn>

you will get filtered records count

1 Like

Thanks @enchev. That works, but in the RadZen designer, I see grid0 doesn't exist in current context.
When I use the following expression in the column footer template.

Filtered Rows: @grid0.View.Count()

It works but the designer doesn't like it. Any hints?
TIA,
Josh

You can try this.grid0.View.Count()

1 Like

The Radzen designer won't recognize the @grid0 ref for the time being. We will add support for that in one of the next releases.

Question - is there any kind of even raised when a user has filtered the grid?

I know you can update the footer to have a count - I have a control elsewhere on the page which I set to the grid count on initialisation. However later when I filter the table the count does not change - I am setting it like this

<RadzenLabel Text="@grid1.View.Count().ToString()" />

Where grid1 is a ref to the grid on my page....

It works for the first time but never get's updated -

If the DataGrid is bound to IQueryable (no matter in-memory or database provider) View (and Count()) will be updated on every filter.

The count is updated within the grid - however is there any way to get a notification that a filter has occurred outside the grid so that an external control will also be updated...

Sadly you cannot update a page variable and use it outside of the grid. I tried with an OnRender event handler and could log it to the console just fine. But setting a page variable never updated the screen. Tried calling StateHasChanged() but that essentially froze the page. An AfterRender method would be good or some way to know when the final render happened so I could call StateHasChanged if that is needed to update my variable.

Invoking StateHasChanged inside the Render event will trigger another Render event and this is why you should not do that.

Thanks for the reply, I know why the page froze. Is there a way to update a page variable so I can show the filtered result count Outside of your grid?

This has been shown before in this thread.

I have taken everything from this article but am not getting it to work. Can we have a complete example of this (showing the Filtered count outside of the Grid?)

My backend code has the IQueryable as mentioned above and my ref:

To show that the refs .View.Count() works INSIDE the grid but not OUTSIDE here is my html.

Here is the page when nothing is filtered and the initial search results are shown. As you can see below, the highlighted 0 is not showing the filtered results (which I am okay with assuming that that number will changed once a Filter is in use.) The highlight under the Type column is to show there are no filters and of course the INSIDE grid filtered count shows the total number.

Lastly, I apply a filter to the Type column of b, highlighted below. My OUTSIDE count is still 0 and the INSIDE count is what we all expect.

I really apologize for taking more of your time, but what can I be missing? I am on 3.18.9.

Maybe the ref isn't updated at the right time (I can't remember when Blazor assigns those).

This seems to work if you handle the Filter event of RadzenDataGrid:

    private int count;

    void OnFilter()
    {
        count = grid1.View.Count();
    }

    protected override void OnInitialized()
    {
        employees = dbContext.Employees;
        count = employees.Count();
    }
1 Like

@korchev that did the trick. Oddly enough, that even triggered something to update my above example's call out of it too! Thank you very much.