Grid FylterType.Excel set from code custum filter

Hi, I'm working on Grid and I select  the FylterType.Excel . I want to set the parameter of the custom filter by Code . 
I can't find a method to do that if I use the method   "Grid.FilterByColumn" I can set only one parameter and not both parameter.

5 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team March 23, 2021 01:20 PM UTC

Hi Matteo, 

Greetings from Syncfusion. 

Query: I can't find a method to do that if I use the method   "Grid.FilterByColumn" I can set only one parameter and not both parameter.  

We have validated your query and we suspect that you want to filter multiple values by using FilterByColumn method. If yes, then you can achieve this requirement by using below way. 

Reference

 
<button @onclick="Filter">Filter multiple values in same column(CustomerID)</button> 
 
<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true" AllowPaging="true"> 
    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings> 
    <GridColumns> 
        . . . 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    SfGrid<Order> Grid { get; set; } 
    . . . 
    public async Task Filter() 
    { 
        await Grid.FilterByColumn("CustomerID", "equal", new List<string> { "ALFKI", "BLONP" }, "or"); 
    } 
} 


If this is not your requirement, then could you please share more information regarding your requirement. It will be helpful to validate and provide a better solution. 

Regards, 
Rahul 



MA Matteo March 23, 2021 01:48 PM UTC

Hi Rahul,

My Objective is to fill out the "custom filter" form by code .
In my particular case I want to filter a date type column  if this date is greater than a generic date or if the date is equal to an empty string.
The methods that you send to me permit you to use only the "equal" condition but I want to use the "greater" condition and "equal" at the same time.

Regards,
Matteo


RS Renjith Singh Rajendran Syncfusion Team March 24, 2021 11:19 AM UTC

Hi Matteo, 

Based on this scenario, we suggest you to add the corresponding column’s filtering query programmatically in FilterSettings.Columns to achieve this requirement. Please refer and use the codes below, 

public async Task Filter() 
{ 
    if (Grid.FilterSettings.Columns == null) 
    { 
        Grid.FilterSettings.Columns = new List<GridFilterColumn>(); 
    } 
    var a = await Grid.GetColumns();   //Get all the Grid columns 
    string fUid = a[2].Uid;            //Fetch the Uid of OrderDate column 
    Grid.FilterSettings.Columns.Add(new GridFilterColumn { Field = "OrderDate", Operator = Syncfusion.Blazor.Operator.GreaterThan, Predicate = "or", Value = new DateTime(2010, 5, 3), Uid = fUid }); 
    Grid.FilterSettings.Columns.Add(new GridFilterColumn { Field = "OrderDate", Operator = Syncfusion.Blazor.Operator.Equal, Predicate = "or", Value = new DateTime(2010, 5, 1), Uid = fUid }); 
    Grid.Refresh();     //Call Refresh to reflect the filtered changes in Grid  
} 


We are also attaching the sample for your reference, please download the sample from the link below, 

Please get back to us if you need further assistance. 

Regards, 
Renjith R 



MA Matteo March 24, 2021 03:13 PM UTC

Hi Renjith,

This is what I was looking for. Only another question if I want to filter where the value is null so where the cell is empty what I have to put  in the "value" properties?


Regards,
Matteo


RN Rahul Narayanasamy Syncfusion Team March 25, 2021 02:19 PM UTC

Hi Matteo, 

Thanks for the update. 

Query: This is what I was looking for. Only another question if I want to filter where the value is null so where the cell is empty what I have to put  in the "value" properties?  

We have validated your query and we suspect that you want know how to filter the null values while using this approach. You can achieve this requirement by defining null in Value property as like below. Find the below code snippets and sample for your reference. 

 
<button @onclick="Filter">Filter multiple values in same column(OrderDate)</button> 
 
<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true"> 
    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings> 
    <GridColumns> 
        . . . 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
    SfGrid<Order> Grid; 
    protected override void OnInitialized() 
    { 
        Orders = Enumerable.Range(1, 75).Select(x => new Order() 
        { 
            OrderID = 1000 + x, 
            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)], 
            Freight = 2.1 * x, 
            OrderDate = (new DateTime?[] { new DateTime(2010, 5, 1), new DateTime(2010, 5, 2), new DateTime(2010, 5, 3),new DateTime(2010, 5, 4),new DateTime(2010, 5, 5), null })[new Random().Next(6)], 
        }).ToList(); 
    } 
 
    . . . 
    public async Task Filter() 
    { 
        if (Grid.FilterSettings.Columns == null) 
        { 
            Grid.FilterSettings.Columns = new List<GridFilterColumn>(); 
        } 
        var a = await Grid.GetColumns();   //Get all the Grid columns 
        string fUid = a[2].Uid;            //Fetch the Uid of OrderDate column 
        Grid.FilterSettings.Columns.Add(new GridFilterColumn { Field = "OrderDate", Operator = Syncfusion.Blazor.Operator.GreaterThan, Predicate = "or", Value = new DateTime(2010, 5, 3), Uid = fUid }); 
        Grid.FilterSettings.Columns.Add(new GridFilterColumn { Field = "OrderDate", Operator = Syncfusion.Blazor.Operator.Equal, Predicate = "or", Value = null, Uid = fUid }); 
        Grid.Refresh();     //Call Refresh to reflect the filtered changes in Grid  
    } 
} 


If this is not your requirement, then could you please share more information regarding your requirement. It will be helpful to validate and provide a better solution. 

Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer
Loader.
Up arrow icon