GetFilteredRecordsAsync with grouped data

Hi,

I noticed that when I call GetFilteredRecordsAsync() on a grid when no grouping is done, I get a List<T> where T is TValue specified for the grid (i.e if I have a SfGrid<Person> I obtain a List<Person>), and that's fine.

If I call GetFilteredRecordsAsync() when record are grouped, I obtain  instead a List<Syncfusion.Blazor.Data.Group<T?> where T? could be my model type (i.e. Person) or another Syncfusion.Blazor.Data.Group if multiple grouping levels exists.

Is there an easy way to get the plain List of my model type when one or more grouping level are currently present in my grid?


6 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team April 20, 2022 02:43 PM UTC

Hi Roberto,


Greetings from Syncfusion support.


We suggest you to check this by using the GetCurrentViewRecordsAsync method of Grid. You can fetch the list of data available in grid’s current view using this method. Please refer the codes below,


    public async Task OnClick()

    {

       var data = await grid.GetCurrentViewRecordsAsync();

    }

 


Reference : https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_GetCurrentViewRecordsAsync


Please check your requirement using this method and if you still face difficulties then kindly get back to us with a detailed explanation of your exact requirement for us to proceed further.


Regards,

Renjith R



RC Roberto Conti April 20, 2022 04:02 PM UTC

Hi Renjit,

I checked your suggested method, but it's not suitable for my needs because in a paginated grid it only returns record from the currently visible page, while GetFilteredRecordsAsync() correctly returns items from all pages (except filtered out records) but when records are grouped the result is not a plain List<TValue> but a List<Group<TValue>> if data is grouped with a single level, or a further nested List if data is grouped with more levels.

Is there a way to obtain the plain List<TValue> from such results?

Thanks

Roberto




RS Renjith Singh Rajendran Syncfusion Team April 21, 2022 01:49 PM UTC

Hi Roberto,


We are currently checking this scenario from our side. We will update you further within two business days on or before April 25, 2022.


Until then we appreciate your patience.


Regards,

Renjith R



MS Monisha Saravanan Syncfusion Team April 25, 2022 02:56 PM UTC

Hi Roberto,


Thanks for the patience.


We would like to inform that we can get filtered data as an list by using the below highlighted changes and we can store the data in to required format as per our need. Kindly check the attached code snippet for your reference.


public async Task GetData()

    {

 

        var filteredRecords = await Grid.GetFilteredRecordsAsync();

        List<string> FilteredItems = new List<string>();

      

 

        foreach (Group<Order> groupData in filteredRecords as List<Group<Order>>)

        {

 

            List<Order> Data = groupData.Items as List<Order>;

            // we can store the data here as an list.

          

            //FilteredItems.Add(groupData.Items.ToString());

          

 

        }

     

    }


Kindly get back to us if you have further queries.


Regards,

Monisha


Marked as answer

RC Roberto Conti April 26, 2022 07:24 AM UTC

Thanks Monisha, that works nicely.




RS Renjith Singh Rajendran Syncfusion Team April 27, 2022 04:53 AM UTC

Hi Roberto,


Thanks for your update. Please get back to us if you need further assistance.


Regards,

Renjith R


Loader.
Up arrow icon