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
close icon

GridGroupingControl - Custom filters with logical expressions on multiple columns


Hi,

I am using GridGroupingControl(asp.net) , I would like to have custom(record) filters on multiple columns with [OR] conditions. Currently the Record filters are working like [AND] condition on multiple columns. Below query is my requirement from coding.

Query - 1:

Get all the records where the 'user1' is present in any of the columns like column1 or column2 or column3.

Query - 2:

Get all the records within date range(start date to end date),
applying expressions to filters.

Also Please suggest the userguide for gridgroupingcontrol.


2 Replies


SN Sridhar N Syncfusion Team January 20, 2012 10:52 AM UTC

Hi Vijay,

Thanks for your patience.

Query #1 "Get all the records where the 'user1' is present in any of the columns like column1 or column2 or column3."

Your requirement can be achieved by adding recordfilters with expertssion. Please refer the below code snippet.

[Codebehind - C#]

void UserFilter_Click(object sender, EventArgs e)
{
this.GridGroupingControl1.TableDescriptor.RecordFilters.Clear();
RecordFilterDescriptor rfd = new RecordFilterDescriptor();
StringBuilder sb = new StringBuilder();
foreach (GridVisibleColumnDescriptor gcd in this.GridGroupingControl1.TableDescriptor.VisibleColumns)
{
sb.AppendFormat("[{0}] like '*{1}*' OR ", gcd.Name, "User1");
}
//'remove last ' OR '
sb.Remove(sb.Length - 4, 4);
rfd.Expression = sb.ToString();
this.GridGroupingControl1.TableDescriptor.RecordFilters.Add(rfd);
this.GridGroupingControl1.DataBind();
}


Query #2 "Get all the records within date range(start date to end date),applying expressions to filters."

Your requiement can be achieved by using logical operator. Please refer the below code snippet.

[Codebehind - C#]

void DateFilter_Click(object sender, EventArgs e)
{
this.GridGroupingControl1.TableDescriptor.RecordFilters.Clear();
GridRecordFilterDescriptor filter2 = new GridRecordFilterDescriptor();
filter2.Name = "Dates";
filter2.LogicalOperator = FilterLogicalOperator.And;
filter2.Conditions.Add(Syncfusion.Grouping.FilterCompareOperator.GreaterThan, "3/24/2005");
filter2.Conditions.Add(Syncfusion.Grouping.FilterCompareOperator.LessThan, "5/10/2005");
this.GridGroupingControl1.TableDescriptor.GridRecordFilters.Add(filter2);
}


For your convenience, we have created sample and the same can be downloaded from the following link.

Custom Filter-1812399385.zip

Please let me know if you have any other questions or concerns.

Regards,
Sridhar.N


Loader.
Live Chat Icon For mobile
Up arrow icon