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

[Solved] Change filter datetime textbox's format

4 Answers 493 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Samnang
Top achievements
Rank 1
Samnang asked on 04 Sep 2009, 10:57 PM
Hi,

I have a requirement to change datetime format from mm/dd/yyyy to yyyy-mm-dd in filter textbox (not the data value).
I am using

datetimeColumn.DataFormatString =

"{0:yyyy-MM-dd}";

but looks like only data value format has changed and filter textbox data format is still MM-dd-yyyy after selecting date from calendar control.

Any idea to fix this.

Thanks,
Sam

 

4 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 07 Sep 2009, 10:37 AM
Hello Sam,

The DateFormat of the filtering date picker can be changed programmatically:

ASPX

<telerik:RadGrid 
    ID="RadGrid1" 
    runat="server" 
    AllowFilteringByColumn="true" 
    OnItemCreated="RadGrid1_ItemCreated" /> 

C#

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    if (e.Item is GridFilteringItem) 
    { 
        ((e.Item as GridFilteringItem)["DateColumnUniqueName"].Controls[0] as RadDatePicker).DateInput.DateFormat = "yyyy-MMM-dd"
    } 


If the date column has no explicit UniqueName set, then the unique name is the corresponding data field.


Sincerely yours,
Dimo
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.
0
Samnang
Top achievements
Rank 1
answered on 08 Sep 2009, 07:51 PM
Thanks.
Sam
0
Bill
Top achievements
Rank 1
answered on 25 Jan 2010, 05:21 PM
My DataFormatString is like so: {0:MMM-DD-YYYY}

Is there anyway to do a Filter Function on a RadGrid like:

1.  Between MMM-DD-YYYY to MMM-DD-YYYY ?

2. Month only?

3. Year only?

My RadGrid Code
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="ProblemsSDS" GridLines="None" 
                Skin="Vista" Style="position: static" AllowFilteringByColumn="True" AllowPaging="True" 
                AllowSorting="True" OnItemInserted="RadGrid1_ItemInserted" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" Width="100%" OnItemCreated="RadGrid1_ItemCreated" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True">  
                <MasterTableView AutoGenerateColumns="False" DataKeyNames="ProblemID" DataSourceID="ProblemsSDS" 
                    CommandItemDisplay="Top">  
<Column> 
<telerik:GridDateTimeColumn DataField="ProblemDate" DataType="System.DateTime" UniqueName="ProblemDate" PickerType="DateTimePicker" FilterImageTooltip="Filter example: mmm-dd-yyyy to mmm-dd-yyyy select 'EqualTo'" 
                            SortExpression="ProblemDate" HeaderText="Problem Date/Time" DataFormatString="{0:MMM-dd-yyyy} {0:t}" FilterControlWidth="125px" DefaultInsertValue="" AllowFiltering="true" CurrentFilterFunction="Between">  
                            <HeaderStyle Width="125px" /> 
                        </telerik:GridDateTimeColumn> 
</Column> 
</RadGrid> 


CS code
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridFilteringItem)  
        {  
            ((e.Item as GridFilteringItem)["ProblemDate"].Controls[0] as RadDatePicker).DateInput.DateFormat = "MMM-dd-yyyy";  
        }   
 
    } 
Thanks,
Bill
0
Yavor
Telerik team
answered on 29 Jan 2010, 06:20 AM
Hello Bill,

To see more information along the lines of the requested information, please refer to the following topic:

http://www.telerik.com/help/aspnet-ajax/grdfilteringfordatetimecolumnwithdataformatstring.html

This can be further modified to handle filtering by date only, or by year only.
I hope this gets you started properly.

Greetings,
Yavor
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
Samnang
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Samnang
Top achievements
Rank 1
Bill
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or