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

Rad grid does not display data

2 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phillip
Top achievements
Rank 1
Phillip asked on 05 Jan 2015, 05:41 PM
I am using an object data source to filter, sort and use custom paging.  The only problem I am having is with the filter for a data/time field.  The data access code called by the object datasource control for the rad grid returns data and a row count 44.  However, no data is displayed in the grid. 

This problem does not make any sense to me.  If the data access code returns rows, the rows should display in the grid.  Data displays when I filter on any row but the data time field.  What could be causing this problem?  I have never worked with filtering a date time field in a rad grid before.

2 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 07 Jan 2015, 01:38 PM
Hi Phillip,

It is possible that the filtering is working correctly, but if you are using the EqualTo filter function, by default, the filter will try to match not only the date, but also the time. For ignoring the time of the DateTime objects you could set the EnableTimeIndependentFiltering property to true for your GridDateTimeColumn. If your column is auto-generated you can handle the server-side OnColumnCreated event:
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    if (e.Column is GridDateTimeColumn)
    {
        (e.Column as GridDateTimeColumn).EnableTimeIndependentFiltering = true;
    }
}

Following is a simple example for RadGrid bound to ObjectDataSource:
<telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="ObjectDataSource1" AllowFilteringByColumn="true" AllowPaging="true" OnColumnCreated="RadGrid1_ColumnCreated">
</telerik:RadGrid>
 
<asp:ObjectDataSource runat="server" ID="ObjectDataSource1" SelectMethod="GetEmployees" SelectCountMethod="SelectCount"
    TypeName="Employees" DataObjectTypeName="Employee" EnablePaging="true"></asp:ObjectDataSource>

And the code-behind:
public static class Employees
{
    public static int SelectCount()
    {
        return 50;
    }
 
    public static List<Employee> GetEmployees()
    {
        List<Employee> employees = new List<Employee>();
        for (int i = 0; i < 50; i++)
        {
            employees.Add(new Employee(i, "Name" + i, DateTime.Now.AddDays(i).AddHours(5)));
        }
 
        return employees;
    }
 
    public static List<Employee> GetEmployees(int startRowIndex, int maximumRows)
    {
        List<Employee> employees = GetEmployees();
        if (maximumRows > SelectCount())
        {
            maximumRows = SelectCount();
        }
 
        employees.GetRange(startRowIndex, maximumRows);
        return employees;
    }
}
 
public class Employee
{
    public int ID { get; set; }
    public string Name { get; set; }
    public DateTime StartDate { get; set; }
    public Employee(int id, string name, DateTime startDate)
    {
        this.ID = id;
        this.Name = name;
        this.StartDate = startDate;
    }
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Phillip
Top achievements
Rank 1
answered on 07 Jan 2015, 07:31 PM
Setting the time independent filtering to true fixed the problem.  Thanks.
Tags
Grid
Asked by
Phillip
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Phillip
Top achievements
Rank 1
Share this question
or