How to customize the isEnable property in PART_OkButton of filtertogglebutton - From 178541

When I click the filtertogglebutton, I am seeing a popup for changing filters. I want to affect " PART_OkButton"'s isEnable property. If filter popup has elements inside, it can be isEnable = true but if it has not any element inside, it must be isEnable = false. I tried to do binding but I saw an error about "cannot find the binding value". 


1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team December 9, 2022 11:53 PM UTC

Hi Kivanc Yilmaz,

Your requirement to customize the isEnable property in PART_OkButton of the filter toggle button in SfDataGrid by customizing the FilterItemsPopulating event. Refer to the below code snippet,


//Event subscription

this.AssociatedObject.FilterItemsPopulating += OnFilterItemsPopulating;

 

//Event customization

private void OnFilterItemsPopulating(object sender, GridFilterItemsPopulatingEventArgs e)

{

    if (e.FilterControl != null)

    {

        //Here gets the PART_OkButton by using reflection in SfDataGrid

        var okButton = (Button)e.FilterControl.GetType().GetField("OkButton", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(e.FilterControl);

 

        //Here get the SfDataGrid

        var sfDataGrid = sender as SfDataGrid;

 

        if(sfDataGrid != null && okButton != null && sfDataGrid.View != null && sfDataGrid.View.Records != null)

        {

            //here checks the condition based on your scenario

            if(sfDataGrid.View.Records.Count == 0)

            {

                //Here disable the PART_OkButton of filtertogglebutton

                okButton.IsEnabled = false;

            }

            else

                //Here enables the PART_OkButton of filtertogglebutton

                okButton.IsEnabled = true;

        }

    }

}


UG Link: https://help.syncfusion.com/wpf/datagrid/filtering#filteritemspopulating-event

Find the sample in the attachment.

Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.




Attachment: Sample_9556630c.zip

Marked as answer
Loader.
Up arrow icon