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

DateTime Filter Problem

4 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 26 Sep 2012, 09:12 PM
I'm trying to use the MonthYearPicker as my control for filtering datetime. However, when I try the code below, I get:

String was not recognized as a valid DateTime.

I've tried formatting several ways with no luck. I was trying to look at the event in the code behind, but I see no arguments at all that contains my filter values themselves. Just the  column name and expression.  Any help would be appreciated. Than you!


<
FilterTemplate>
                     
                    <telerik:RadMonthYearPicker ID="RadMonthYearPicker1" runat="server" ClientEvents-OnPopupClosing="MeasurementDateChanged" />
 
                            <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">
 
                                <script type="text/javascript">
                                    function MeasurementDateChanged(sender, args) {
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                        var year = args._picker.FocusedDate[0];
                                        var month = args._picker.FocusedDate[1];
 
                                        var fromDate = new Date(year, month-1, 1);
                                        var toDate = new Date(year, month, 0);
 
 
                                        tableView.filter("MeasurementDate", fromDate.toISOString() + " " + toDate.toISOString(), "Between");
                                    }
                                </script>
 
                            </telerik:RadScriptBlock>
                    </FilterTemplate>

4 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 26 Sep 2012, 09:37 PM
Woops! Can someone please move this to the ASP.NET AJAX section?
0
Eyup
Telerik team
answered on 01 Oct 2012, 10:45 AM
Hello Michael,

This error usually is related to your DataField type. Could you please verify that all of the items from the field you are trying to filter are of type System.DateTime?

Please temporarily create a GridDateTimeColumn and set its DataField property to your Date field and see whether the issue still remains.

Looking forward to your reply.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Michael
Top achievements
Rank 1
answered on 01 Oct 2012, 03:46 PM
GridDateTimeColumnworks fine, but I'm needing to use the filtertemplate because I want to use the month picker, not date....
0
Eyup
Telerik team
answered on 03 Oct 2012, 02:24 PM
Hi Michael,

Could you please try the following approach?
<telerik:GridBoundColumn UniqueName="MeasurementDate" HeaderText="Measurement Date" DataField="OrderDate">
    <FilterTemplate>
        <telerik:RadMonthYearPicker ID="RadMonthYearPicker1" runat="server" ClientEvents-OnDateSelected="MeasurementDateChanged" />
        <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">
            <script type="text/javascript">
                function MeasurementDateChanged(sender, args) {
                    var year = args.get_newDate().getUTCFullYear();
                    var month = args.get_newDate().getUTCMonth();
                    var fromDate = new Date(year, month - 1, 1);
                    var toDate = new Date(year, month, 0);
                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                    tableView.filter("MeasurementDate", fromDate.toISOString() + " " + toDate.toISOString(), "Between");
                }
            </script>
        </telerik:RadScriptBlock>
    </FilterTemplate>
</telerik:GridBoundColumn>

I hope this will prove helpful. It works properly on my end. Please give it a try and let me know about the result.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or