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

Hierarchical grids - using date as child grid parameter

1 Answer 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matias
Top achievements
Rank 1
Matias asked on 20 Apr 2016, 06:07 PM

I have 2 grids that work correcly, but one of the parameters used to get the data of the child grid is a date with a format that varies when using different web browsers.

When the controller action recieves the date, the string has different values according to the browser used. For example:

-IE: "Mon Oct 17 00:00:00 UTC-0300 2016"
-Chrome: "Mon Oct 17 2016 00:00:00 GMT-0300 (Hora estándar de Argentina)"
-Firefox: "Mon Oct 17 2016 00:00:00 GMT-0300"

I'd like to know if I can format the date before sending it to the controller.

This are my grids:

PARENT GRID:
@(Html.Kendo().Grid(Model)
        .Name("ParentGrid")
        .DataSource(dataSource => dataSource
        .Ajax()
            .Read(read => read.Action("Read", "controller")
            .Data("ParameterFunction"))
        .PageSize(30)
        )
        .Columns(columns =>
        {
            columns.Bound(foo => foo.fecha_venc).Title(Global.Fecha).Format("{0:dd/MM/yyyy}"); //This is the date I need formatted
            columns.Bound(foo => foo.espe_codigo).Title(Global.Especie);
            columns.Bound(foo => foo.clas_codigo).Title(Global.Clase);
           
        })
        .ClientDetailTemplateId("template")
    )

 

CHILD GRID:
@(Html.Kendo().Grid<SGMTrade.DAL.ViewModels.OperacionesOCTPorFecha>()
        .Name("ChildGrid")
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(10)
            .Read(read => read.Action("childGrid_Read", "controller", new { fecha = "#=fecha_venc#", especie = "#=espe_codigo#", cliente = @ViewBag.cliente, clase = "#=clas_codigo#" }))
        )
        .Columns(columns =>
        {
            columns.Bound(o => o.oper_numero).Title(Global.NumeroOperacion)
            .ClientTemplate("<a href='\\\\\\#' onclick=\"showDetails('\\#=oper_numero\\#')\">\\#=oper_numero\\#</a>");
            columns.Bound(o => o.oper_forigen).Title(Global.FechaOrigen).Format("{0:dd/MM/yyyy}");
            columns.Bound(o => o.espe_codigo).Title(Global.Especie);
            columns.Bound(o => o.clas_codigo).Title(Global.Clase);
        })
        .ToClientTemplate()
    )

 

CONTROLLER ACTION:

public ActionResult childGrid_Read([DataSourceRequest]DataSourceRequest request, string fecha, string especie, string cliente, string clase)
        {
            //the string fecha comes with the wrong formatting, and I need it to come as dd/MM/yyyy
        }

 

Thank you very much

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 25 Apr 2016, 07:15 AM
Hello Matias ,

Since the dates are created on the client when the response from the server is returned - the dates are always created with an offset according to the timezone of the browser:
You can try to create date in the browser's console and see the result (you will see the difference if your timezone is different than the UTC 0):
new Date("2012-01-12T18:45"); 

Thus said, I suggest you to take a look at this code library:

http://www.kendoui.com/code-library/mvc/grid/using-utc-time-on-both-client-and-server-sides.aspx


Regards,
Maria Ilieva
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
Matias
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or