This is a migrated thread and some comments may be shown as answers.

[Solved] Applying filtering across two columns from outside controls

1 Answer 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jonathan hart
Top achievements
Rank 1
jonathan hart asked on 17 Nov 2009, 08:13 PM

I have a UI which needs filtering activated. 

The scrum story reads, "As a user I want to filter grid rows using calendar controls to select a start date and an end date."

There are two columns in the grid:  Job Start, and Job End. I need to apply the following filter logic:
JobStart >= calendarStartDate AND JobEnd < calendarEndDate. 

The routine executes in the event handler of the "apply filter" button.

Can someone please tell me what I am doing wrong?

        protected void UpdateButton_OnClick(object sender, EventArgs args)  
        {  
            //First attempt was to directly edit the filter expression  
            //this._jobReportsSummaryGrid.Grid.MasterTableView.FilterExpression = string.Format("[JobStart] >= '{0}' AND [JobEnd] < '{1}'", _startDateCalendar.SelectedDate, _endDateCalendar.SelectedDate);  
              
 
            //When that didn't work I added this   
            this._jobReportsSummaryGrid.Grid.AllowFilteringByColumn = true;              
            GridColumn JobStartColumn = this._jobReportsSummaryGrid.Grid.MasterTableView.GetColumnSafe("JobStart");  
            JobStartColumn.CurrentFilterFunction = GridKnownFunction.GreaterThanOrEqualTo;  
            JobStartColumn.CurrentFilterValue = _startDateCalendar.SelectedDate.Value.Date.ToString("MM/dd/yyyy");              
 
            GridColumn JobEndColumn = this._jobReportsSummaryGrid.Grid.MasterTableView.GetColumnSafe("JobEnd");  
            JobEndColumn.CurrentFilterFunction = GridKnownFunction.LessThan;  
            JobEndColumn.CurrentFilterValue = _startDateCalendar.SelectedDate.Value.Date.ToString("MM/dd/yyyy");  
              
            //...and when that didn't work, I came here  
        } 

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 20 Nov 2009, 09:16 AM
Hi jonathan,

You need to set the FilterExpression property of the MasterTableView and rebind the grid.  This is enough to filter the grid. A valid filter expression should be specified as follows:

- (with EnableLinqExpressions=true)
(DateTime?(it[\"BirthDate\"]) > DateTime.Parse(\"1/1/1900\")) AND (DateTime?(it[\"HireDate\"]) < DateTime.Parse(\"1/1/1910\"))

- (with EnableLinqExpresssions=false)
([BirthDate] > '1/1/1900') AND ([HireDate] < '1/1/1910')


I hope this helps.

Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
jonathan hart
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or