Grid client template and date formats

8 posts, 1 answers
  1. Dima
    Dima avatar
    5 posts
    Member since:
    Feb 2013

    Posted 04 Mar 2013 Link to this post

    Hi,

    How can I  format my date to MM/dd/yyyy in client template? It seems that Format method doesn't work for client templates. Also, I need to sort column that contains date.

    Thanks in advance,
    Dzmitry Shmidt
  2. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2287 posts

    Posted 04 Mar 2013 Link to this post

    Hello Dzmitry,

    When using template the formation must be handled within the template. For example:

    {
     field: "BirthDate",
     title: "Birth Date",
     template: '#= kendo.toString(BirthDate,"dd/MM/yyyy") #'
    }

    You can find more details by inspecting the code in the following demo:
    http://demos.kendoui.com/web/grid/index.html
    http://docs.kendoui.com/getting-started/framework/globalization/dateformatting
    All the best,
    Nikolay Rusev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Dima
    Dima avatar
    5 posts
    Member since:
    Feb 2013

    Posted 04 Mar 2013 Link to this post

    Thanks Nikolay for you reply,
    Sorry but i didn't mention, that i used asp.net mvc and want to write as little javascript code as possible. Now when i used date time it's displayed as /Date(.......)/ format. Is there any way to do this on the server and don't use javascript.

    Thanks in advance,
    Dzmitry Shmidt
  4. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2287 posts

    Posted 05 Mar 2013 Link to this post

    Hello Dzmitry,

    If you describe the fields in the DataSource.schema and mark them with correct types it will automatically convert those values to correct JavaScript types. For more details see the configuration for the date field in the following demo:
    http://demos.kendoui.com/web/grid/remote-data.html

    Regards,
    Nikolay Rusev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Raimundo
    Raimundo avatar
    2 posts
    Member since:
    Dec 2012

    Posted 02 Apr 2015 in reply to Nikolay Rusev Link to this post

    Nikolay if we use CLIENTTEMPLATE, with AJAX, your answer (http://demos.kendoui.com/web/grid/remote-data.html) doesn't fix the problem.

    Could you provide some code about it, with Razor?

  6. Raimundo
    Raimundo avatar
    2 posts
    Member since:
    Dec 2012

    Posted 02 Apr 2015 in reply to Raimundo Link to this post

    Nikolay if we use CLIENTTEMPLATE, with AJAX, your answer (http://demos.kendoui.com/web/grid/remote-data.html) doesn't fix the problem.

    Could you provide some code about it, with Razor?

    For instance:

    .ClientTemplate(
    string.Format("<spam style='background-color: green; text-align:right;'>{0:yyyy}}</spam>", "#:ShipDate#")
    );
  7. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2598 posts

    Posted 06 Apr 2015 Link to this post

    Hello Raimundo,

    What my colleague suggested is to set the type of the data that you get from the server to be date, so the Grid will know to parse the data to valid JavaScript objects. How to define a model is explained here:

    http://docs.telerik.com/kendo-ui/api/javascript/data/model#configuration-Define

    If this does not help, please send us a send a runnable sample and we will be happy to help.

    Regards,
    Kiril Nikolov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  8. Imran
    Imran avatar
    7 posts
    Member since:
    Jun 2015

    Posted 23 Jul 2015 Link to this post

    This thing worked for me good

     

    c.Bound(p => p.datetimecalculated).Format("{0:dd-MM-yyyy}");​

Back to Top