Filtering on collection property

We have a grid which uses a column template to display the contents of a small a collection property in a single column.

We'd like for users to be able to filter on this column - for example allowing them to select 'France' from the dropdown and see all entries where the list of countries includes France in the grid below.

Is there any way to define a filter that achieves this behaviour>

<SfGrid @ref="@Grid" AllowFiltering="true" AllowPaging="true" TValue="Organisation">
    <GridEvents OnActionFailure="HandleActionFailure" TValue="Organisation"></GridEvents>
    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings>
    <SfDataManager Url="@EndpointProvider.OrganisationsEndpoint" CrossDomain="false" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>
    <GridPageSettings PageSize="10"></GridPageSettings>
    <GridColumns>
        <GridColumn Field="@nameof(Organisation.Id)" HeaderText="Organisation ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
        <GridColumn Field="@($"{nameof(Organisation.Countries)}")" HeaderText="Countries" Width="150">
            <Template>
                @{
                    foreach (CountryPresence countryPresence in (context as Organisation).CountryPresences)
                    {
                        Country country = countryData[countryPresence.CountryId];
                        <CountryIndicator text="@(country.ShortName)" />
                    }
                }
            </Template>
        </GridColumn>
    </GridColumns>
</SfGrid>

5 Replies

JP Jeevakanth Palaniappan Syncfusion Team November 26, 2020 10:22 AM UTC

Hi Robert, 

Greetings from Syncfusion support. 

We have validated your query and we suspect that you need to filter the values based on the values you have rendered by using the column template. If so we would like to inform you that the column template feature is used only to display the customized element value or content in the UI. In grid the data operations like filtering, sorting, grouping etc. will only be performed based on the values set to the field columns which is the default behavior. To achieve your requirement you have to set the values to be filtered in a separate column. 


Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 



RO RobertSullivan November 27, 2020 09:45 AM UTC

Hi Jeevakanth,

That's not quite it - we don't want to filter on the rendered data, we want to filter on the collection property that backs that rendered data.

I appreciate that filtering doesn't apply based on the column template - I was just wondering if there was a way to filter on a collection-valued property (in this case an ICollection<CountryScope>).

Thanks,

Rob


JP Jeevakanth Palaniappan Syncfusion Team November 30, 2020 01:35 PM UTC

Hi Robert, 

We suspect that you need to do any one of the below two cases. 

  1. Do you need to do filtering operation for one to many relationship columns? Like a List<string> type property bounded to grid and you need to do filtering for this column by using an external dropdown.
  2. Do you need to filter a complex column bounded to the grid by using an external dropdown?

To validate your requirement we suggest you to share us the organisation model class with the complete grid code which will be helpful for us to know the exact requirement and provide you with a better solution as early as possible. 

Regards, 
Jeevakanth SP. 



RO RobertSullivan November 30, 2020 03:57 PM UTC

Hi Jeevakanth,

Option (1) is the right idea, though (1) it would be preferable to do the filtering within the grid if possible (rather than using an external dropdown) and (2) rather than a list of strings, it's a list of models returned by the OData backend with an id from which the string can be looked up.

An Organisation looks like:

public class Organisation {
    public Guid Id {get; set;}
    public ICollection<CountryPresenceCountryPresences {get; set;}
}

public class CountryPresence {
    public Guid OrganisationId {get; set;}
    public Guid CountryId {get; set;}
}

There's also a Country class:

public class Country {
    public Guid Id {get; set;}
    public string ShortName {get; set;}
}

The code for the grid is:

.@code {
    [Inject]
    private IODataEndpointProvider EndpointProvider { get; set; }
    [Inject]
    private ICountryProvider CountryProvider { get; set; }

    private SfGrid<Organisation> Grid { get; set; }

    private Dictionary<Guid, Country> countryLookup = new Dictionary<Guid, Country>();

    protected override async Task OnInitializedAsync()
    {
        ICollection<Country> countries = await CountryProvider.GetAll();
        countryLookup = countries.ToDictionary(c => c.Id, c => c);
    }
}

<SfGrid @ref="@Grid" AllowFiltering="true" AllowPaging="true" TValue="Organisation">
    <GridEvents TValue="Organisation"></GridEvents>
    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings>
    <SfDataManager Url="@EndpointProvider.OrganisationsEndpoint" CrossDomain="false" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>
    <GridPageSettings PageSize="10"></GridPageSettings>
    <GridColumns>
        <GridColumn Field="@nameof(Organisation.Id)" HeaderText="Organisation ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
        <GridColumn Field="@($"{nameof(Organisation.CountryPresences)}")" HeaderText="Countries" Width="150">
            <Template>
                @{
                    foreach (CountryPresence countryPresence in (context as Organisation).CountryPresences)
                    {
                        Country country = countryData[countryPresence.CountryId];
                        <CountryIndicator text="@(country.ShortName)" />
                    }
                }
            </Template>
        </GridColumn>
    </GridColumns>
</SfGrid>
Thanks,

Rob


JP Jeevakanth Palaniappan Syncfusion Team December 1, 2020 11:59 AM UTC

Hi Robert, 

Thanks for sharing the details. We have confirmed that you need to perform data operation(filtering) for one to many relationship column. For this requirement we have already logged a feature task “Need to provide data operation support for one to many relationship columns” for the same. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision and technological feasibility. It will be implemented in any of our upcoming releases. 
 
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.     


Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon