How to use FilterRow to add filtered content in the code behind and display it on the FilterRowEditorType control of the corresponding column in the U

How to use FilterRow to add filtered content in the code behind and display it on the FilterRowEditorType control of the corresponding column in the UI


3 Replies

MS Malini Selvarasu Syncfusion Team January 3, 2025 12:05 PM UTC

Hi zkey wang,

Based on the information provided, we understand that you need to update the FilterText in the Filter Row when filtering is applied programmatically from the code-behind. This can be achieved by setting the column's `FilteringFrom` property to `FilterRow`, which indicates that the column is being filtered through the Filter Row. As a result, the `FilterText` is correctly updated in the Filter Row.

To assist you further, we have prepared a sample demonstrating this approach. Please review the sample and the accompanying code snippet, and let us know if it aligns with your requirements.
Code snippet:
sfdatagrid.ItemsSourceChanged += Sfdatagrid_ItemsSourceChanged;
private void Sfdatagrid_ItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e)
{
    var column = sfdatagrid.Columns["OrderID"];
    column.FilterPredicates.Add(new FilterPredicate()
    {
        FilterBehavior = FilterBehavior.StronglyTyped,
        FilterMode = ColumnFilter.Value,
        FilterType = FilterType.NotEquals,
        FilterValue = "1005"
    });
  column.FilteredFrom = FilteredFrom.FilterRow;
}
If we’ve misunderstood your request or if your requirements differ, please share additional details to help us better understand your needs and provide a more tailored solution.
Thank you for your cooperation and understanding.
Regards,
Malini Selvarasu


Attachment: SfDataGrid_Demo_fd169211.zip


ZW zkey wang January 4, 2025 01:46 AM UTC

Sfdatagrid_ItemsSourceChanged can indeed be implemented. In the demo, I also learned to use column.FilteredFrom = FilteredFrom.FilterRow; but it needs to be triggered when the ItemsSource does not change. For example, if I write it on button click, the content of FilterRow will not be displayed. When the mouse is clicked, it is displayed, and when the mouse is moved away, it is hidden again.

Image_1707_1735955163959

Image_1942_1735955188040



Attachment: SfDataGrid_Demo_fd169211_af81e947.rar


MS Malini Selvarasu Syncfusion Team January 6, 2025 02:54 PM UTC

Hi zkey wang,

Thank you for providing detailed information about the issue you are encountering. Upon reviewing the reported scenario, we observed that the `filterRowText` is not updated correctly when the filter is applied using the button click event.

From our investigation, it appears that the `Column.FilteredFrom` option is being defined after the `filterPredicates` are added. When the `filterPredicates` are set, the filtering process is executed. However, before updating the `filterRowText`, we check if the `FilteredFrom` value is set to `FilterRow`. Since the `FilteredFrom` is defined after the `filterPredicates`, the `FilterRow` value is not updated as expected.
In the `SourceCollectionChanged` event, you can define the `FilteredFrom` property at any point. This is because the filtering process is re-executed after the grid and view have fully loaded, ensuring that the issue does not occur in this scenario.
Additionally, when entering edit mode in the `FilterRow`, we update the `FilterControlEditValue`, ensuring the value is updated correctly.
To resolve this issue, we recommend defining the `FilteredFrom` as `FilterRow` *before* adding the `filterPredicates`. This ensures the filtering process and text updates occur as intended. Please review the below code snippet,
Code Snippet:
private void Button_Click(object sender, RoutedEventArgs e)
{
     var column = sfdatagrid.Columns["OrderID"];
     column.FilteredFrom = FilteredFrom.FilterRow;
     column.FilterPredicates.Add(new FilterPredicate()
     {
         FilterBehavior = FilterBehavior.StronglyTyped,
         FilterMode = ColumnFilter.Value,
         FilterType = FilterType.Equals,
         FilterValue = "1005"
     });
}
If we’ve misunderstood your request or if your requirements differ, please share additional details to help us better understand your needs and provide a more tailored solution.
Thank you for your cooperation and understanding.
Regards,
Malini Selvarasu

Loader.
Up arrow icon