Custom Filtering for EditType.DropDownEdit

I have a SfGrid that has a column that uses the DropDownEdit control.  I have allowed filtering on the drop down control and would like to implement a custom filter using a query object like I have done on a SfDropDownList.  Is this possible and if so how?

thanks in advance


1 Reply 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team January 11, 2021 11:54 AM UTC

Hi William, 

Greetings from Syncfusion support. 
 
Query: would like to implement a custom filter using a query object like I have done on a SfDropDownList. 
 
We have validated your query and we suspect that you want to filter the dropdown list in a grid column as like you did for a separate SfDropDownList. You can do the same by rendering SfDropDownList component in EditTemplate of the GridColumn. Find the below code snippets and sample for your reference to use the EditTemplate. 

<SfGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings> 
    <GridEvents OnActionBegin="ActionBeginHandler" TValue="Order"></GridEvents> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" ValidationRules="@(new ValidationRules{ Required=true})" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150"> 
            <EditTemplate> 
                <SfDropDownList TValue="string" @ref="ddlObj" TItem="Countries" Placeholder="Select a game" DataSource="@Country" AllowFiltering="true"> 
                    <DropDownListFieldSettings Value="Name"></DropDownListFieldSettings> 
                    <DropDownListEvents TValue="string" TItem="Countries" ValueChange="ValueChange" Filtering="OnFilter"></DropDownListEvents> 
                </SfDropDownList> 
            </EditTemplate> 
        </GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
 
    private async Task OnFilter(FilteringEventArgs args) 
    { 
        args.PreventDefaultAction = true; 
        var query = new Query().Where(new WhereFilter() { Field = "Name", Operator = "contains", value = args.Text, IgnoreCase = true }); 
 
        query = !string.IsNullOrEmpty(args.Text) ? query : new Query(); 
 
        await ddlObj.Filter(Country1, query); 
    } 
 
    public void ActionBeginHandler(ActionEventArgs<Order> args) 
    { 
       if (DropDownValue != string.Empty && args.Action == "Edit" && args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save)) 
        { 
            args.Data.ShipCountry = DropDownValue; 
            DropDownValue = string.Empty; 
        } 
    } 
 
    public void ValueChange(ChangeEventArgs<string, Countries> args) 
   { 
        DropDownValue = args.Value; 
    } 
} 



Documentation Reference: 

Please let us know if you have any concerns. 

Regards, 
Jeevakanth SP. 



Marked as answer
Loader.
Up arrow icon