0

So I instead of using a texfield to filter date in my grid filter i added a datepicker. The problem that I'm having is that the datepicker on filtering is sending a different format output to my controller that I can't really format.

It returning my dates like "Fri Mar 30 2018 00:00:00 GMT+0200 (Romance Summer Time)". What I want my filter to do is to keep the format from my UI. This date format is not suitable in my application because depending on the user geographycal location he may have a different dateformat standaard so telerikui will send a different output everytime. I would have to check for every possibility in this case.

Grid:

@(Html.Kendo().Grid<EmployeeHistoryViewModel>()
                      .Name("gridEmployeeHistoryList")
                      .Columns(columns =>
                      {
                          columns.Bound(c => c.Action).Title(GlobalResources.Action);
                          columns.Bound(c => c.ActionTakenOn).Title(GlobalResources.ActionTakenOn).Filterable(f => f.UI("ANAB.Employee.employeehistoryDetail.DateTimeFilter"));
                          columns.Bound(c => c.Actor).Title(GlobalResources.Actor);
                          columns.Bound(c => c.FieldName).Title(GlobalResources.FieldName);
                          columns.Bound(c => c.OldValue).Title(GlobalResources.OldValue);
                          columns.Bound(c => c.NewValue).Title(GlobalResources.NewValue);
                      })
                      .HtmlAttributes(new { style = "height: 550px;" })
                      .Scrollable()
                      .Events(ev => ev.DataBound("ANAB.addGridIcons"))
                      .Selectable(selectable =>
                      {
                          selectable.Mode(GridSelectionMode.Single);
                          selectable.Type(GridSelectionType.Row);
                      })
                      .Filterable(filter =>
                      {
                          filter.Extra(false);
                          filter.Operators(op =>
                          {
                              op.ForString(str =>
                              {
                                  str.Clear().Contains("Contains");
                              });
                              op.ForDate(date =>
                              {
                                  date.Clear().IsEqualTo("required format: " + @ANABAppContext.GetDateFormat());
                              });
                          });
                      })
                      .Resizable(resize => resize.Columns(true))
                      .Sortable()
                      .Pageable(pageable => pageable
                          .Refresh(true)
                          .ButtonCount(5))
                      .DataSource(dataSource => dataSource
                          .Ajax()
                          .Model(model => model.Id(p => p.Id))
                          .Read(read => read.Action("GetEmployeeHistoryList", "Employee", new { employeeId = Model.Id }))
                          .PageSize(ANABAppContext.GetPageSize())
                        )
        )

JS:

var DateTimeFilter = function (control) {
    $(control).kendoDatePicker({
        format: ANAB.Employee.employeehistoryDetail.options.dateFormat,
        parseFormats: ANAB.Employee.employeehistoryDetail.options.dateFormat,
    });
}
Pedro Lopes
  • 479
  • 2
  • 9
  • 20
  • You have a date that is being returned with the data and you would like the user to be able to filter that data based on a date displayed in their own time zone? What time zone is the date field stored in? – Ross Bush Mar 06 '18 at 14:29
  • ANAB.Employee.employeehistoryDetail.options.dateFormat is returning the dateformat of the geographycal location of the user. So if the User is in India he will get other format then me in Europe. The output the datepicker is returning in my controller is "Fri Mar 30 2018 00:00:00 GMT+0200 (Romance Summer Time)" this is autogenerated by the component and i have no control over this output atm. What i want is for this output format to be the same format as ANAB.Employee.employeehistoryDetail.options.dateFormat since I can manipulata the date with it easier afterwards – Pedro Lopes Mar 06 '18 at 14:36
  • Do you store the TimeZone information for your users? – Ross Bush Mar 06 '18 at 14:52
  • I have the culture and the dateformat stored in my database – Pedro Lopes Mar 06 '18 at 15:05
  • I would guess if you convert the date fields from the TZ the DateTime is stored in to the clients TZ representation prior to returning the data to the grid then it should be more inline with your expectations. – Ross Bush Mar 06 '18 at 16:09

0 Answers0