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

RadGrid "Date Between" Filtering

3 Answers 540 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 13 Mar 2014, 05:10 PM
Hello,

I am using a RadGrid with filtering capability on multiple columns and have run into an issue. Background: the users want the grid to default to only items that were created in the current fiscal year. I have already applied the initial filter in the NeedDataSource event as follows:

ASPX:
                <telerik:GridDateTimeColumn DataField="Created" HeaderText="Submitted Date" SortExpression="Created" DataFormatString="{0:d}"
                    FilterControlWidth="120px" UniqueName="Created" PickerType="DatePicker" EnableRangeFiltering="true">
                    <HeaderStyle Width="150px" />
                </telerik:GridDateTimeColumn>

ASPX.CS (in NeedDataSource function after grid DataSource is set)
        if (!Page.IsPostBack)
        {
            RadGrid1.MasterTableView.FilterExpression = string.Format("([Created] >= \'{0:d}\') AND ([Created] <= \'{1:d}\')", FiscalYearStart, FiscalYearEnd);
            GridColumn createdDate = rgRevenueAdjustments.MasterTableView.GetColumnSafe("Created");
            createdDate.CurrentFilterFunction = GridKnownFunction.Between;
            createdDate.CurrentFilterValue = FiscalYearStart.ToShortDateString();
            createdDate.AndCurrentFilterValue = FiscalYearEnd.ToShortDateString();
        }

This all works fine, with the exception that the filter values do not appear in the RadDatePickers, as shown below:

 
The main issue I'm trying to solve is that when a user filters on another column, the filter for this column is removed, where I want it to filter down the existing items. I've tried to do some searching around to solve this, and haven't really found any answers yet. Am I missing something?

As a side note: I would really love for the RadDatePickers to appear on two lines rather than expanding out horizontally. Is this possible?

3 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 13 Mar 2014, 05:13 PM
It appears my image didn't post. Regardless, there are two datepickers side by side with no value entered. I just thought it might be easier to visualize.
0
Shinu
Top achievements
Rank 2
answered on 14 Mar 2014, 05:04 AM
Hi Matt,

I guess you want to show the values in the two filter textbox which is enabled through the RangeFiltering. Please try the following code snippet. You can display the date fields separated by a space as shown below.

C#:
if (!Page.IsPostBack)
{
  RadGrid1.MasterTableView.FilterExpression = "(([Created] >= '12/12/12') AND ([Created] <= '08/08/13'))";
  GridColumn createdDate = RadGrid1.MasterTableView.GetColumnSafe("Created");
  createdDate.CurrentFilterFunction = GridKnownFunction.Between;
  createdDate.CurrentFilterValue = "12/12/12 08/08/13"; //To display the two dates separate it with space
}

Thanks,
Shinu
0
Matt
Top achievements
Rank 1
answered on 14 Mar 2014, 01:10 PM
Perfect! Thanks so much
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or