Get only possible filter values on custom filter

Hi,


I have a custom filter on SfGrid, something like:

<FilterTemplate>

    <SfTreeView TValue="DateTimeCheckBoxObject" ShowCheckBox="true" AutoCheck="true" LoadOnDemand="false">

    <TreeViewEvents TValue="DateTimeCheckBoxObject" NodeChecked="NodeCheckedHandler" DataSourceChanged="DataSourceChangedHandler"></TreeViewEvents>

    <TreeViewFieldsSettings TValue="DateTimeCheckBoxObject" Id="Id" DataSource="@TreeData" Text="DisplayString" ParentID="ParentId" HasChildren="HasChild" Expanded="Expanded" IsChecked="IsChecked"></TreeViewFieldsSettings>

</SfTreeView>

</FilterTemplate>


My goal is to only list possible column values in the SfTreeView. For example, if another filter on another column in the grid has removed half of the datasource, i only want to show values in this filter that havent been filtered out by other columns. (The built in Excel filter works this way currently). Importantly i do want to show items that have been filtered by this column (e.g. if i deselect an item in the tree view which hides it from the grid, i still want that item to appear in the custom filter).


Is there a built in method/property that contains what im looking for? 


Thanks,

Harry



1 Reply

SK Sanjay Kumar Suresh Syncfusion Team January 20, 2025 11:18 AM UTC

Hi Harry,


When reviewing your query about customizing the filter template using the TreeView component, it seems you want to display only the current record values. To achieve this, you can use the GetFilteredRecordsAsync method to obtain the records in the grid after filtering. This will allow you to customize your filter template as needed.


Concern Code Snippet:

public async Task FilteredHandler(Syncfusion.Blazor.Grids.FilteredEventArgs args)

{

     var filteredRecords = await Grid.GetFilteredRecordsAsync(); // to get the current filtered records

 

     if ((filteredRecords as List<OrderData>).Count == GridData.Count)

     {

         TreeViewData = GridData.GroupBy(e => e.ShipCity).Select(g => g.First()).ToList(); // to show only distinct values.

         return; // clear filtering action has been performed on this scenario.

     }

     TreeViewData = filteredRecords as List<OrderData>;

}


Sample:

https://blazorplayground.syncfusion.com/embed/VjByNWhZKvEKTlkR?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5


For You Reference:

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


Feel free to reach out if you need any further assistance.


Regards,

Sanjay Kumar Suresh


Loader.
Up arrow icon