We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

apply the filter from a button

I have an enum in my model. I want to apply the filter from a button for my component 


if i click the button for that the filter will apply for the table

how i can this ?

if I click, so that it only leaves the rows with my enum value

        private FileTypeGaraj GetGarajState(param1, param2)
        {

            if (condition)
            {
                return VariableModel = FileTypeMission.enumString1;
            }
            if (Icondition)
            {
                return VariableModel = FileTypeMission.enumString2;
            }
            return VariableModel = FileTypeMission.enumString3; ;
        }
    }

    public enum FileTypeGaraj
    {
        enumString1,
        enumString2,
        enumString3
    }

 

<SfGrid @ref="Grid" DataSource="monSource" Height="550" AllowReordering="true" AllowFiltering="true" AllowPaging="true" AllowSorting="true">
            <GridEvents TValue="MonValue" RowDataBound="RowBound"></GridEvents>          
            <GridPageSettings PageSize="15"></GridPageSettings>
            <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.CheckBox" IgnoreAccent="true" ShowFilterBarStatus="true" Mode="FilterBarMode.Immediate" ImmediateModeDelay="300" Operators=Operator.Contains>
            </GridFilterSettings>
            <GridColumns>
                <GridColumn Field=MyField HeaderText=MyHeaderText Width="90" Type=ColumnType.String></GridColumn>
                <GridColumn Field=MyField HeaderText=MyHeaderText Width="90" Type=ColumnType.String></GridColumn>
                <GridColumn Field=MyField HeaderText=MyHeaderText Width="90" Type=ColumnType.String></GridColumn>
                ...

               
            </GridColumns>
</SfGrid>



    public void OnCliCkBtnFiler()
    {
        var toto = MyEnum.param1;
        if (modelTable != null)
            foreach (var toto2 in modelTable)
            {
                toto = toto2.VariableEnumTypeValue;
                if (toto == MyEnum.param2)
                {
                    //filter my Grid Table
                }
            }
    }

1 Reply 1 reply marked as answer

MS Monisha Saravanan Syncfusion Team March 24, 2023 06:54 AM UTC


Hi,


Greetings from Syncfusion support


We would like to inform that we have inbuilt method to perform filtering externally. By using FilterByColumnsAsync method we can perform filtering programmatically. We have also documented the topic in the below UG section. Kindly check the attached sample and code snippet for your reference.


Reference: https://blazor.syncfusion.com/documentation/datagrid/filtering#filter-enum-column


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


 

<Syncfusion.Blazor.Buttons.SfButton @onclick="Click">Filter</Syncfusion.Blazor.Buttons.SfButton>

<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true">

    <GridColumns>

       

    </GridColumns>

</SfGrid>

 

 

@code {

 

    public enum FileType : short

    {

        Base = 1,

        Replace = 2,

        Delta = 3

    }

    public async Task Click()

    {

        await this.Grid.FilterByColumnAsync("Type", "contains", FileType.Base);

    }

}



Please let us know if you have any concerns.


Regards,

Monisha


Attachment: BlazorApp1_2e9e0b5e.zip

Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon