Clear datepicker filter from radgrid

4 posts, 0 answers
  1. Shannon Borho
    Shannon Borho avatar
    1 posts
    Member since:
    Oct 2009

    Posted 04 May 2011 Link to this post

    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.
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 06 May 2011 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Massimiliano
    Massimiliano avatar
    2 posts
    Member since:
    Nov 2015

    Posted 14 Apr Link to this post

    Hi, do you have resolve ?
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 15 Apr Link to this post

    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.
Back to Top