Filter grid based on 2 columns compare

I'd like to filter the grid to only show rows where the value of ColumnA is greater than the value in ColumnB
The filtering options I see, only allow to filter a column based on a static value.
Please advise.

5 Replies

VN Vignesh Natarajan Syncfusion Team April 27, 2020 12:08 PM UTC

Hi Charlie,  
 
Greetings from Syncfusion support.  
 
Query: “I'd like to filter the grid to only show rows where the value of ColumnA is greater than the value in ColumnB 
 
From your query we understand that you want to filter the record by comparing two column values. Can you please share the following details to validate query further.  
 
  1. Share  the type of Datasource you are have bound to Grid.
  2. Share the details about the column you want to compare.
  3. Do you want to apply filter during the initial render or a external button click.
  4. Share more details about your requirement.
 
Above requested details will be helpful for us to validate the reported query at our end and provide solution as early as possible.      
 
Regards, 
Vignesh Natarajan 



PP Pete Pfeifer April 27, 2020 06:21 PM UTC

Hi Vignesh,

1. Datasource is a List
2. The columns are both numeric
3. I want to run this filter from a button click
4. For example I have 2 columns columnA has the quantity sold in last 30 days, columnB has quantity sold last year for the same 30 days. I need to filter and show only records where columnA is greater than columnB. 



VN Vignesh Natarajan Syncfusion Team April 29, 2020 04:04 PM UTC

Hi Charlie,  
 
Thanks for the update.  
 
Query: “I have 2 columns columnA has the quantity sold in last 30 days, columnB has quantity sold last year for the same 30 days. I need to filter and show only records where columnA is greater than columnB 
 
Currently we are validating your query we will update you the further details by 4th May 2020. Till then we appreciate your patience.  
 
Regards, 
Vignesh Natarajan 



PP Pete Pfeifer May 4, 2020 03:48 PM UTC

Thank you, looking forward.


RS Renjith Singh Rajendran Syncfusion Team May 5, 2020 12:03 PM UTC

Hi Charlie, 

Based on your requirement, we suggest you to filter your List based on your scenario and assign that filtered value to Grid’s DataSource property variable. We have prepared a sample based on this requirement. Please download eth sample from the link below, 

Please refer the code below, 

 
<SfButton OnClick="FilterGrid">Filter</SfButton> 
 
<SfGrid TValue="Order" @ref="GridInstance" DataSource="@Orders" ... > 
    ... 
</SfGrid> 
 
@code{ 
    SfGrid<Order> GridInstance; 
    public List<Order> Orders { get; set; } 
    public List<Order> FilteredValue = new List<Order>(); 
    public void FilterGrid() 
    { 
        foreach(var a in Orders) 
        { 
            if(a.EmployeeID > a.Freight) 
            { 
                FilteredValue.Add(a); 
            } 
        } 
        Orders = FilteredValue; 
    } 
    ... 
} 


Please refer the below documentation on changing the Grid’s DataSource dynamically, 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Loader.
Up arrow icon