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

Clear datepicker filter from radgrid

3 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shannon Borho
Top achievements
Rank 1
Shannon Borho asked on 04 May 2011, 04:41 PM
I am attempting to do something similar to this but slightly different. I am attempting to put a raddatepicker in a radgrid filter template with the textbox disabled so the user cannot enter a date and must use the datepicker button. Then I want to have an imagebutton next to the datepicker that will clear the filter. The datepicker works as expected and filters the radgrid appropriately but clicking the imagebutton does not clear the filter. Here is my code for the column including javascript:

<telerik:GridTemplateColumn DataField="openDate" DataType="System.DateTime" HeaderText="Open Date"
    SortExpression="openDate" UniqueName="openDate" ReadOnly="True" FilterControlAltText="Filter open date">
    <HeaderStyle Width="150px" />
    <FilterTemplate>
        <telerik:RadDatePicker ID="OpenedRadDatePicker" runat="server" ClientEvents-OnDateSelected="OpenDateSelected"
            DbSelectedDate='<%# SetOpenedDate(Container) %>' DateInput-DisplayDateFormat="yyyy/MM/dd"
            Culture="en-US">
            <Calendar ID="OpenedRadDatePickerCalendar" runat="server" UseColumnHeadersAsSelectors="False"
                UseRowHeadersAsSelectors="False" ViewSelectorText="x">
            </Calendar>
            <DateInput ID="OpenedRadDatePickerDateInput" runat="server" DateFormat="yyyy/MM/dd"
                DisplayDateFormat="yyyy/MM/dd" Enabled="false">
                <ClientEvents OnLoad="OnClientLoad" />
            </DateInput>
            <DatePopupButton HoverImageUrl="" ImageUrl="" />
            <ClientEvents OnDateSelected="OpenDateSelected" />
        </telerik:RadDatePicker>
        <asp:ImageButton ID="ClearOpenDateButton" runat="server" ImageUrl="images/cancel.gif"
            AlternateText="Show All" ToolTip="Clear Open Date Filter" Style="vertical-align: middle"
            Height="15px" Width="15px" OnClientClick="ClearDateSelected(); return true;" />
        <telerik:RadScriptBlock ID="OpenDateSelectedRadScriptBlock" runat="server">
            <script type="text/javascript">
                var datePicker;
                function OnClientLoad(sender, args) {
                    datePicker = sender;
                }
 
                function ClearDateSelected() {
                    datePicker.clear();
                }
 
                function OpenDateSelected(sender, args) {
                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                    var date = FormatSelectedDate(sender);
                    var nextDate = GetNextSelectedDate(sender);
                    if (date != "" && nextDate != "") {
                        tableView.filter("openDate", date + " " + nextDate, Telerik.Web.UI.GridFilterFunction.Between);
                    }
                    else {
                        tableView.filter("openDate", "", Telerik.Web.UI.GridFilterFunction.NoFilter);
                    }
                }
 
                function FormatSelectedDate(picker) {
                    var formattedDate = "";
                    var date = picker.get_selectedDate();
                    if (date != null) {
                        var dateInput = picker.get_dateInput();
                        formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, "M/d/yyyy");
                    }
 
                    return formattedDate;
                }
                function GetNextSelectedDate(picker) {
                    var formattedDate = "";
                    var date = picker.get_selectedDate();
 
                    if (date != null) {
                        date.setDate(date.getDate() + 1);
                        var dateInput = picker.get_dateInput();
                        formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, "M/d/yyyy");
                    }
 
                    return formattedDate;
                }
            </script>
        </telerik:RadScriptBlock>
    </FilterTemplate>
    <ItemTemplate>
        <asp:Label runat="server" ID="openDateLabel" Text='<%# Eval("openDate", "{0:yyyy/MM/dd}") %>'></asp:Label>
    </ItemTemplate>
</telerik:GridTemplateColumn>
 
 
protected DateTime? SetOpenedDate(GridItem item)
{
    string openFilter = item.OwnerTableView.GetColumn("openDate").CurrentFilterValue;
    if (string.IsNullOrEmpty(openFilter))
    {
        return new DateTime?();
    }
    else
    {
        return DateTime.Parse(openFilter.Substring(0, openFilter.IndexOf(" ")));
    }
}

When I press the ClearOpenDateButton while the radgrid is filtered, I do get the partial page postback. The RadGrid_ItemCommand event is properly fired, the LinqDataSource Selecting and Selected events run correctly as well and in the Selected event, it does indeed indicate in the arguments that all rows are being returned from the datasource but the grid doesn't get updated. I'm thinking it's just an update problem but I'm not sure why it works fine with the raddatepicker but not the imagebutton.

Also when I press the ClearOpenDateButton, the datepicker does clear the selected date as expected.

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 06 May 2011, 02:31 PM
Hello Shannon,

Please, refer to the support ticket post for additional information. In order to avoid duplicate posts, I will ask you to continue our communication there.

Kind regards,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Massimiliano
Top achievements
Rank 1
answered on 14 Apr 2016, 10:13 AM
Hi, do you have resolve ?
0
Pavlina
Telerik team
answered on 15 Apr 2016, 03:02 PM
Hi Massimiliano,

As this post is too old I would recommend you open a new support ticket, describe your scenario in details, specify if you are using the latest version of Telerik.UI for ASP.NET AJAX, elaborate what is the desired behavior and we will gladly assist you.

Thank you for your understanding.

Regards,
Pavlina
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Shannon Borho
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Massimiliano
Top achievements
Rank 1
Share this question
or