How to get the count of filtered rows from Syncfusion Blazor Grid?

Query: How to get the count of filtered rows from Syncfusion Blazor Grid?


Answer:
The filtered rows count can be retrieved through GetFilteredRecords() method. Here is the code for your reference,

@using Newtonsoft.Json 

 

public int FilterCount { getset; } 

... 

public async Task GetFilterCount() 

{ 

    var a = await Grid.GetFilteredRecords(); 

    FilterCount = JsonConvert.DeserializeObject<List<Order>>(JsonConvert.SerializeObject(a)).Count(); 

} 



5 Replies

JM Juan Manuel December 20, 2020 08:14 PM UTC

This does not work when the grid is grouping.


RS Renjith Singh Rajendran Syncfusion Team December 21, 2020 09:22 AM UTC

Hi Juan, 

Greetings from Syncfusion support. 

We suggest you to use as like the below code to overcome the reported problem you are facing. 

 
public async Task GetFilterCount() 
{ 
    var a = await Grid.GetFilteredRecords(); 
    FilterCount = JsonConvert.DeserializeObject<List<object>>(JsonConvert.SerializeObject(a)).Count(); 
} 


Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



TA Tobias Andraschko April 29, 2021 02:30 PM UTC

This just returns the number of the groups in which the data is structured.

I would rather want to have the total item count of every group.

Is this possible?






TA Tobias Andraschko April 29, 2021 02:36 PM UTC

I found a way with temporarily deactivating the AllowGrouping property of the grid.. i don't know, is that the right way?

private async void ActionCompleteHandler(ActionEventArgs<MTask> args)
{
  if (args.RequestType == Syncfusion.Blazor.Grids.Action.Searching)
  {
    m_Grid.AllowGrouping = false;
    var groupedResult = JsonConvert.DeserializeObject<List<object>>(
      JsonConvert.SerializeObject(await m_Grid.GetFilteredRecords()));

    m_FilteredRecords = groupedResult.Count();
    m_Grid.AllowGrouping = true;
  }
}


RS Renjith Singh Rajendran Syncfusion Team April 30, 2021 09:09 AM UTC

Hi Tobias, 

Greetings from Syncfusion support. 

We have checked this scenario with the shared solution. We could see that you would like to fetch the searched record result during searching action in Grid.  

Yes, you can use this solution to achieve your requirement. Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Loader.
Up arrow icon