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

GridBoundColumn Date Filter does not work

3 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 10 Feb 2016, 10:33 AM

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>

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 15 Feb 2016, 08:51 AM
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
0
Christian
Top achievements
Rank 1
answered on 16 Feb 2016, 10:11 AM

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.

0
Eyup
Telerik team
answered on 19 Feb 2016, 07:53 AM
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
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Christian
Top achievements
Rank 1
Share this question
or