Number of grouped rows in grid

Hi everybody,

   is there a way to get the number of grouped and filtered rows in a grid ?

I would like to have information like: (grouped count) of (complete / filtered count) Records. This is very handy for "on the fly" statistics like "how ,many different items do I have in my data" or checking for duplicate rows on certain fields.

I could get the ungrouped initial number by calling Grid.DataSource.Count().ToString() in OnAfterRender. 
But using OnActionComplete which should be the correct event for grouping and filtering according to your documentation did not show the desired information. Most of the properties were null.

To be precise: 
What events are called when applying a filter or a grouping ?
Where and how can I get the number of the filtered / grouped records ?
  regards
    Uwe



5 Replies

RS Renjith Singh Rajendran Syncfusion Team May 11, 2020 12:31 PM UTC

Hi Uwe, 

Greetings from Syncfusion support. 

Query 1 : What events are called when applying a filter or a grouping ? 
Both the Action events(OnActionBegin and OnActionComplete) will be triggered when performing filtering/grouping actions in Grid. 
 
Query 2 : Where and how can I get the number of the filtered / grouped records ? 
You can get the filtered records count by using the GetFilteredRecords method of Grid, inside the OnActionComplete event handler by checking for the RequestType as Filtering. Please refer the code below, 

 
    <GridEvents OnActionComplete="OnActionComplete" TValue="Order"></GridEvents> 
 
    public async Task OnActionComplete(ActionEventArgs<Order> args) 
    { 
        if(args.RequestType.ToString() == "Filtering") 
        { 
            var filterdata = await DefaultGrid.GetFilteredRecords(); 
        } 
   } 



And during grouping action, the Grid’s record count will not be changed. Just the total available records in Grid will be grouped, and there won’t be any change in the total records count of Grid. So if you are Grouping a Grid after performing filtering, then you can use the above suggested GetFilteredRecords method to find the total available records in Grid after filtering. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



UH Uwe Hein May 11, 2020 04:42 PM UTC

Hi Renjith Singh Rajendran

  thanks for your fast answer and for guiding my attention to the grid property instead of the args parameter. So I could get the filtered record count. 

Concerning the grouped count:
How about using CurrentViewData for this ? Counting this object seems to fulfil my purpose.

Last Question:
How do I get the filter expression like on the bottom of the paging when paging is false. Do I have to iterate over all columns for a set filter or is there a property for this ?

   regards

        Uwe



RS Renjith Singh Rajendran Syncfusion Team May 12, 2020 11:26 AM UTC

Hi Uwe, 

Thanks for your update. 

Query 1 : How do I get the filter expression like on the bottom of the paging when paging is false. 
We suggest you to get the Filter column and value details in the OnActionComplete event handler and store them as Dictionary values to achieve this requirement. You can use this stored Dictionary to iterate and display the Filter column information. We have also prepared a sample based on this scenario. Please download the sample form the link below, 
 
Please refer the codes below, 

 
<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true" AllowPaging="true"> 
    <GridEvents OnActionComplete="OnActionComplete" TValue="Order"></GridEvents> 
    ... 
</SfGrid> 
 
@foreach (var a in FilterStatus) 
{ 
    <div>@a.Key : @a.Value</div> 
} 
 
 
@code{ 
    SfGrid<Order> Grid; 
    public List<Order> Orders { get; set; } 
    private Dictionary<string, object> FilterStatus { get; set; } = new Dictionary<string, object>(); 
    public string ColumnName { get; set; } 
    public object FilterValue { get; set; } 
    ... 
   public void OnActionComplete(ActionEventArgs<Order> args) 
    { 
        if (args.RequestType.ToString() == "Filtering") 
        { 
            if (FilterStatus.ContainsKey(args.CurrentFilterObject.Field)) 
            { 
                FilterStatus.Remove(args.CurrentFilterObject.Field);    //Remove the filter column details during clear filtering 
                if(args.CurrentFilterObject.Value != "") 
                { 
                    FilterStatus.Add(args.CurrentFilterObject.Field, args.CurrentFilterObject.Value); //Add if same column is filtered again with different value 
                } 
            } 
            else 
            { 
                FilterStatus.Add(args.CurrentFilterObject.Field, args.CurrentFilterObject.Value); //Add details during filtering 
            } 
        } 
    } 
    ... 
} 


Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



UH Uwe Hein May 12, 2020 03:54 PM UTC

Hi Renjith Singh Rajendran,

   thank you - works !!

    regards

       Uwe


RS Renjith Singh Rajendran Syncfusion Team May 13, 2020 04:56 AM UTC

Hi Uwe, 

Thanks for your update. 

We are glad to hear that our suggestion helped you in achieving your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Loader.
Up arrow icon