GridBoundColumn Date Filter does not work

4 posts, 0 answers
  1. Christian
    Christian avatar
    2 posts
    Member since:
    Aug 2011

    Posted 10 Feb Link to this post

    Hi, I have the following Code to filter a GridBoundColumn. The data comes from a Microsoft SQL DB. For some reason the filtering is not working.

     

    <telerik:GridBoundColumn DataField="TestTimeStamp"
                        UniqueName="TestTimeStamp" HeaderButtonType="TextButton"
                        HeaderText="<%$ Resources:Repository,ReportingTimeStamp%>" DataType="System.DateTime"
                        DataFormatString="{0:g}">
                        <FilterTemplate>
                            From
                                <telerik:RadDatePicker ID="FromOrderDatePicker2" runat="server"
                                    Width="150px" DbSelectedDate='<%# startDate %>'>
                                    <ClientEvents OnDateSelected="FromDateSelected" />
                                </telerik:RadDatePicker>
                            <br />
                            to
                                <div style="padding-left: 31px;">
                                    <telerik:RadDatePicker ID="ToOrderDatePicker2" runat="server"
                                        Width="150px" DbSelectedDate='<%# endDate %>'>
                                        <ClientEvents OnDateSelected="ToDateSelected" />
                                    </telerik:RadDatePicker>
                                </div>
                            <telerik:RadScriptBlock ID="scriptFilterEventDate" runat="server">
                                <script type="text/javascript">
                                    function FromDateSelected(sender, args) {
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                        var ToPicker = $find('<%# ((GridItem)Container).FindControl("ToOrderDatePicker2").ClientID %>');
     
                                        var fromDate = FormatSelectedDate(sender);
                                        var toDate = FormatSelectedDate(ToPicker);
     
                                        if (toDate != '') {
                                            tableView.filter("TestTimeStamp", fromDate + " " + toDate, "Between", true);
                                            //tableView.filter("TestTimeStamp", fromDate, Telerik.Web.UI.GridFilterFunction.GreaterThan);
                                        }
                                    }
     
                                    function ToDateSelected(sender, args) {
                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                        var FromPicker = $find('<%# ((GridItem)Container).FindControl("FromOrderDatePicker2").ClientID %>');
     
                                        var fromDate = FormatSelectedDate(FromPicker);
                                        var toDate = FormatSelectedDate(sender);
     
                                        if (fromDate != '') {
                                            //tableView.filter("TestTimeStamp", fromDate, Telerik.Web.UI.GridFilterFunction.GreaterThan);
                                            tableView.filter("TestTimeStamp", fromDate + " " + toDate, "Between", true);
                                        }
                                    }
     
                                    function FormatSelectedDate(picker) {
                                        var date = picker.get_selectedDate();
                                        var dateInput = picker.get_dateInput();
                                        var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());
     
                                        return formattedDate;
                                    }
                                </script>
                            </telerik:RadScriptBlock>
                        </FilterTemplate>
                    </telerik:GridBoundColumn>

  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 15 Feb Link to this post

    Hello Christian,

    Please use the built-in range filtering provided by RadGrid:
    http://teleriknext.com/forums/filtering-issues-f154584cbb0b#K4cEr7lxV0O0GYt4ib3GrA

    Also, make sure that you are not using DataBind() to bind the grid. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
    Declarative DataSource
    Programmatic Data Binding


    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Christian
    Christian avatar
    2 posts
    Member since:
    Aug 2011

    Posted 16 Feb in reply to Eyup Link to this post

    Hello Eyup,

    if you take a look at my posted code snipped, I am exactly doing it like in your example. But it still doesn´t work. One of the two filter is ignored all the time.

  5. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 19 Feb Link to this post

    Hello Christian,

    Do you use the Between function as demonstrated in the template example? Again, I recommend that you switch to using the built-in range filtering provided by the GridDateTimeColumn as explained in the post in the provided link:

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top