I am looking for a solution to an issue with date filtering in the Kendo grid control.
Below are example MVC code segments for this issue. We are currently on Kendo 2018.2.620.440 version.
Issue:
The issue is that the grid date being displayed and used for filtering is incorrect in that it is minus one day. The web server is running
in UTC time and I the client are running in US Central Time. I understand how to use the client template for the column to display the date
correctly using a string property of the date, but in order to filter we need to be filtering on the date property so that the filter menu
displays for dates (IsEqualTo, IsGreaterThanOrEqualTo, IsLessThanOrEqualTo). If I change the column to use a string date property
the filter menu display entries for text filtering, not date filtering.
Running the code locally has no issue since the web server and client are running in the same zone. It's when the web server is
running in a different zone. I understand that the Kendo grid is converting the date from the server (running in UTC) to the client zone.
Is there a way to stop this or what can I set on the server date object so it would not convert the date.
Code:
------------------------------------------------------------------------------------------------
Model: UserAccountModel.cs
public class UserAccountModel
{
public UserAccountModel();
public string ID { get; set; }
public DateTime? BirthDate { get; set; }
public string DisplayName { get; set; }
}
}
------------------------------------------------------------------------------------------------
View: MemberAccounts.cshtml
<div class="row">
@(Html.Kendo().Grid<UserAccountModel>(appEmpList)
.Name("MemberApplicationDatesGrid")
.HtmlAttributes(new { @class = "editor-grid" })
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(3)
)
.Columns(columns =>
{
columns.Bound(e => e.BirthDate).Format("{0:d}").Sortable(true).Filterable(true).Title("Date");
columns.Bound(e => e.DisplayName).Filterable(true).Sortable(true).Title("Name");
})
.Scrollable()
.Resizable(r => r.Columns(true))
.Sortable(sortable => sortable
.AllowUnsort(false)
.SortMode(GridSortMode.SingleColumn))
.Filterable(filterable => filterable
.Extra(false)
.Messages(msg => msg.Clear("Clear"))
.Mode(GridFilterMode.Menu).Operators(operators => operators
.ForDate(date => date.Clear()
.IsEqualTo("Equal To")
.IsGreaterThanOrEqualTo("Greater Than Or Equal To")
.IsLessThanOrEqualTo("Less Than Or Equal To")
)
)
)
.DataSource(d => d.Ajax()
.Events(e => e.Error("onWebApiError"))
.Model(m => m.Id(e => e.ID))
.ServerOperation(false)
.PageSize(10)
)
)
</div>
------------------------------------------------------------------------------------------------
Controller Method: MemberBase.cs
[HttpGet]
public ActionResult MemberAccounts()
{
//set mock data
List<UserAccountModel> appMbrList = new List<UserAccountModel>();
for (int idx = 0; idx < 20; idx++)
{
appMbrList.Add(new UserAccountModel()
{
BirthDate = DateTime.Now.AddYears(-idx).Date,
ID = idx.ToString(),
DisplayName = "Name-" + idx.ToString()
});
}
ActionResult actionResult = this.View(appMbrList);
return actionResult;
}
Below are example MVC code segments for this issue. We are currently on Kendo 2018.2.620.440 version.
Issue:
The issue is that the grid date being displayed and used for filtering is incorrect in that it is minus one day. The web server is running
in UTC time and I the client are running in US Central Time. I understand how to use the client template for the column to display the date
correctly using a string property of the date, but in order to filter we need to be filtering on the date property so that the filter menu
displays for dates (IsEqualTo, IsGreaterThanOrEqualTo, IsLessThanOrEqualTo). If I change the column to use a string date property
the filter menu display entries for text filtering, not date filtering.
Running the code locally has no issue since the web server and client are running in the same zone. It's when the web server is
running in a different zone. I understand that the Kendo grid is converting the date from the server (running in UTC) to the client zone.
Is there a way to stop this or what can I set on the server date object so it would not convert the date.
Code:
------------------------------------------------------------------------------------------------
Model: UserAccountModel.cs
public class UserAccountModel
{
public UserAccountModel();
public string ID { get; set; }
public DateTime? BirthDate { get; set; }
public string DisplayName { get; set; }
}
}
------------------------------------------------------------------------------------------------
View: MemberAccounts.cshtml
<div class="row">
@(Html.Kendo().Grid<UserAccountModel>(appEmpList)
.Name("MemberApplicationDatesGrid")
.HtmlAttributes(new { @class = "editor-grid" })
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(3)
)
.Columns(columns =>
{
columns.Bound(e => e.BirthDate).Format("{0:d}").Sortable(true).Filterable(true).Title("Date");
columns.Bound(e => e.DisplayName).Filterable(true).Sortable(true).Title("Name");
})
.Scrollable()
.Resizable(r => r.Columns(true))
.Sortable(sortable => sortable
.AllowUnsort(false)
.SortMode(GridSortMode.SingleColumn))
.Filterable(filterable => filterable
.Extra(false)
.Messages(msg => msg.Clear("Clear"))
.Mode(GridFilterMode.Menu).Operators(operators => operators
.ForDate(date => date.Clear()
.IsEqualTo("Equal To")
.IsGreaterThanOrEqualTo("Greater Than Or Equal To")
.IsLessThanOrEqualTo("Less Than Or Equal To")
)
)
)
.DataSource(d => d.Ajax()
.Events(e => e.Error("onWebApiError"))
.Model(m => m.Id(e => e.ID))
.ServerOperation(false)
.PageSize(10)
)
)
</div>
------------------------------------------------------------------------------------------------
Controller Method: MemberBase.cs
[HttpGet]
public ActionResult MemberAccounts()
{
//set mock data
List<UserAccountModel> appMbrList = new List<UserAccountModel>();
for (int idx = 0; idx < 20; idx++)
{
appMbrList.Add(new UserAccountModel()
{
BirthDate = DateTime.Now.AddYears(-idx).Date,
ID = idx.ToString(),
DisplayName = "Name-" + idx.ToString()
});
}
ActionResult actionResult = this.View(appMbrList);
return actionResult;
}