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

How to change DateTime filter dropdownlist's value?

2 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pam Redrum
Top achievements
Rank 1
Pam Redrum asked on 01 Jun 2010, 03:10 AM
I have using a custom filter operation, so after ItemCommond function
if (e.CommandName == RadGrid.FilterCommandName)
I set e.Canceled = true
But I want the datetime filter have the right selected item at the dropdownlist(NoFilter, GreaterThan or so)
I try to change the FilterMenu in Init, but I set it to selected and no use.
part code is

<telerik:RadGrid ID="RGViewMEdia" Skin="someSkin" EnableEmbeddedSkins="false" 
            runat="server" CssClass="list_one" AutoGenerateColumns="False" AllowPaging="True" 
            GridLines="None" Width="800px" DataKeyNames="somefield" AllowAutomaticDeletes="True" 
            AllowSorting="True" ShowStatusBar="True" AllowFilteringByColumn="true" DefaultSortDirection="Descending" 
            DefaultSortExpression="somefield" BorderStyle="None" PageSize="10" AllowCustomPaging="true" OnInit="RGViewMEdia_Init" 
            OnItemCommand="RGViewMEdia_ItemCommand" OnNeedDataSource="RGViewMEdia_NeedDataSource" OnItemDataBound="RGViewMEdia_ItemDataBound" 
            OnSortCommand="RGViewMEdia_ItemSortCommand" OnPageIndexChanged="RGViewMEdia_PageChangeCommand"
 
...... 
...... 
 
<telerik:GridDateTimeColumn DataField="somedatefield" HeaderText="DateTime" ReadOnly="True" UniqueName="PublishDate" DataType="System.DateTime" 
                        SortExpression="somedatefield" DataFormatString="{0:dd.MM.yyyy}" ItemStyle-Width="80px" FilterListOptions="VaryByDataType" 
                        PickerType="DatePicker" FilterControlWidth="60px"/> 
 
...... 
some code behind is
protected void RGViewMEdia_ItemCommand(object sender, GridCommandEventArgs e) 
        { 
            if (e.CommandName == RadGrid.FilterCommandName) 
... 
                RGViewMEdia.CurrentPageIndex = 0; 
                RGViewMEdia.Rebind();                
                e.Canceled = true
 
protected void RGViewMEdia_Init(object sender, EventArgs e) 
        { 
            GridFilterMenu menu = RGViewMEdia.FilterMenu; 
            // Iterate through the items backwards 
            // so that the indexing is not thrown off 
            // when items are removed! 
            for (int i = menu.Items.Count - 1; i >= 0; i--) 
            { 
                if (menu.Items[i].Text.IndexOf("Null")>=0) 
                { 
                    menu.Items.RemoveAt(i); 
                } 
                else if (menu.Items[i].Text.IndexOf("EqualTo") >= 0 && menu.Items[i].Text.IndexOf("Than") < 0) 
                { 
                    menu.Items.RemoveAt(i); 
                } 
                                 
            } 
 
            if (Expression!=null&&Expression.PublicationDateOperate != DateOperate.NoFilter) 
            { 
                string operate; 
                switch (Expression.PublicationDateOperate) 
                { 
                    case DateOperate.GreaterThan: 
                        operate = "GreaterThan"
                        break
                    case DateOperate.GreaterThanOrEqualTo: 
                        operate = "GreaterThanOrEqualTo"
                        break
                    case DateOperate.LessThan: 
                        operate = "LessThan"
                        break
                    case DateOperate.LessThanOrEqualTo: 
                        operate = "LessThanOrEqualTo"
                        break
                    default
                        operate = "NoFilter"
                        break
                } 
                RadMenuItem item = menu.Items.FindItem(i => i.Text == operate); 
                if(item!=null
                    item.Selected = true
            } 
        } 


2 Answers, 1 is accepted

Sort by
0
Pam Redrum
Top achievements
Rank 1
answered on 01 Jun 2010, 09:53 AM
I have tried use RGViewMEdia.MasterTableView.FilterExpression = string.Format("([somedatefield] {0} '{1}')", ">", datevalue) in RGProductList_ItemCommand
but seems no use too (the datetime filter's dropdownlist do not select the GreaterThan)


0
Radoslav
Telerik team
answered on 04 Jun 2010, 07:36 AM
Hello Pam,

To achieve the desired functionality you could try setting the filtered column's CurrentFilterFunction and CurrentFilterValue properties. For example:
protected void RadGrid1_PreRender(object sender, System.EventArgs e)
{
  if (Expression!=null&&Expression.PublicationDateOperate != DateOperate.NoFilter)
  {
    GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("ColumnUniqueName");
    column.CurrentFilterFunction = GridKnownFunction.Contains;
    column.CurrentFilterValue = "EnteredFilterValue";
    RadGrid1.MasterTableView.Rebind();
  }
}

I hope this helps.

All the best,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Pam Redrum
Top achievements
Rank 1
Answers by
Pam Redrum
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or