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

GridDateTimeColumn unable to filter using RadDateTimePicker

1 Answer 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rajesh
Top achievements
Rank 1
Rajesh asked on 30 Apr 2014, 10:13 AM
I'm having trouble in filtering the columns using the RadDateTimePicker for the GridDateTimeColumn. I'm getting the error 'The string was not recognized as a valid DateTime.' I verified the formats and seems to be proper. I used the following code,

<telerik:GridDateTimeColumn UniqueName="EventDate" DataField="Date" SortExpression="Date" DataFormatString="{0:MMMM, dd, yyyy HH:mm:ss}" DataType="System.DateTime">
                                                <HeaderStyle Wrap="False" Width="20%"></HeaderStyle>
                                                <ItemStyle Wrap="False" HorizontalAlign="Left" Width="20%"></ItemStyle>
                                                <FilterTemplate>
                                                    From
                                                    <telerik:RadDateTimePicker ID="FromOrderDatePicker" runat="server" Width="140px" ClientEvents-OnDateSelected="FromDateSelected" />
                                                        
                                                    To
                                                    <telerik:RadDateTimePicker ID="ToOrderDatePicker" runat="server" Width="140px" ClientEvents-OnDateSelected="ToDateSelected" />
                                                    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                                                        <script type="text/javascript">
                                                            function FromDateSelected(sender, args) {
                                                                var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                                var ToPicker = $find('<%# ((GridItem)Container).FindControl("ToOrderDatePicker").ClientID %>');

                                                                var fromDate = FormatSelectedDate(sender);
                                                                var toDate = FormatSelectedDate(ToPicker););

                                                                console.log(fromDate + " " + toDate);

                                                                tableView.filter("EventDate", fromDate + " " + toDate, "Between");

                                                            }
                                                            function ToDateSelected(sender, args) {
                                                                var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                                var FromPicker = $find('<%# ((GridItem)Container).FindControl("FromOrderDatePicker").ClientID %>');

                                                                var fromDate = FormatSelectedDate(FromPicker);
                                                                var toDate = FormatSelectedDate(sender);
                                                                
                                                                console.log(fromDate + " " + toDate);

                                                                tableView.filter("EventDate", fromDate + " " + toDate, "Between");
                                                            }
                                                            function FormatSelectedDate(picker) {
                                                                var date = picker.get_selectedDate();
                                                                var dateInput = picker.get_dateInput();

                                                                console.log("1 -> " + date + " " + dateInput);

                                                                var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, "M/dd/yyyy hh:mm:ss tt");
                                                                //var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());

                                                                return formattedDate;
                                                            }
                                                        </script>
                                                    </telerik:RadScriptBlock>
                                                </FilterTemplate>
                                            </telerik:GridDateTimeColumn>. 


I'm getting the following print for the from and to date,
"4/23/2014 12:00:00 AM     -       4/24/2014 12:00:00 AM "

Please help. I want to filter based on both date and time. 
 








1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 30 Apr 2014, 04:29 PM
Hi Rajesh,

Since Q2 2012 version of Telerik UI controls GridDateTimeColumn has an EnableRangeFiltering and EnableTimeIndependentFiltering properties. Range filtering function allows user to use between filtering for date/time columns out of the box. While the time independent filtering disregards the time portion of the date/time object when filtering the datasource. For a live example which demonstrates this functionality you can refer to demo linked below:
http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/basic-filtering/defaultcs.aspx

More information about GridDateTimeColumn filtering is available here:
http://www.telerik.com/help/aspnet-ajax/grid-rangefiltering-datetime-column.html

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Rajesh
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or