Date formatting in Grid

4 posts, 0 answers
  1. Lars
    Lars  avatar
    11 posts
    Member since:
    Jul 2015

    Posted 09 Feb Link to this post

    Hi Everybody, 

      I have some questions about the way the ClientTemplates are working inside the Grid. 
      Today I have the following code.
        Which are working fine. 

    @(Html.Kendo().Grid<Felix.DomainModel.BusinessEntities.ManuallyCreatedEntities.LandsforeningerModel>
                        ().BindTo(Model.Countries).Name("Countries")
                        .ToolBar(configurator =>
                        {
                            configurator.Create();
                        })
                        .Editable(e => e.Mode(GridEditMode.InCell).CreateAt(GridInsertRowPosition.Bottom))
                .Events(e => e.Edit("onEditItem")).Events(e => e.Save("onSaveItemLandsForening"))
                        .Columns(columns =>
                        {
                            columns.Bound(m => m.Name).Encoded(true).EditorTemplateName("RelatedCountries").ClientTemplate("#= Name #" +
                            "<input type='hidden' name='Countries[#= indexCountries(data)#].Name' value='#= Name#' />" +
                            "<input type='hidden' name='Countries[#= indexCountries(data)#].Id' value='#= Id #' />"
                            );
                            columns.Bound(m => m.Startdate).Width(150).Encoded(true).ClientTemplate("#= kendo.toString(kendo.parseDate(Startdate,'dd/MM/yyyy'), '" + "dd-MM-yyyy" + "') #" +
                            "<input type='hidden' name='Countries[#= indexCountries(data) #].Startdate' value='#= Convert2StringDate(Startdate) #' />").Format("{0: dd-MM-yyyy}");
     
                            columns.Command(m => m.Destroy()).Width(100);
     
                        })
                        .DataSource(dataSource => dataSource.Ajax()
                        .Model(model =>
                        {
                            model.Id(p => p.Id);
                        })
                        ))

    My question: is it possible to allow more formats in the input field, like ddMMyy and ddMMYYYY and not only dd-MM-YYYY. 

    How should this be done?

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 11 Feb Link to this post

    Hello Lars,

     

    First I would like to mention that ClientTemplate will override the builder methods such Format and etc. Given this you can safely remove the .Format("{0: dd-MM-yyyy}");

     

    I am not sure that I understand completely what you are trying to achieve. The DateTime value will be printed in the column cell using the following expression: 

    #= kendo.toString(kendo.parseDate(Startdate,'dd/MM/yyyy'), '" + "dd-MM-yyyy" + "')

    It will parse and show the output to the grid. How you can use different format in this case?

    Regards,
    Boyan Dimitrov
    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Lars
    Lars  avatar
    11 posts
    Member since:
    Jul 2015

    Posted 11 Feb in reply to Boyan Dimitrov Link to this post

    Hi Boyan, 

     I will remove the format part of the razor code. 

     I wan't to achive multiple input formats from the user:

    They should be able to insert this: ddMMyy -> dd-MM-yyyy or ddMMyyyy -> dd-MM-yyyy

  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 15 Feb Link to this post

    Hello Lars,

     

    The HTML input element does not have such capabilities. My suggestion is to include the Kendo UI DatePicker widget in the template to achieve similar functionality. What the Kendo UI DatePicker offers is a parseFormats option, which allows specifying a list of date formats used to parse the value set with value() method or by direct user input.

     

    Regards,
    Boyan Dimitrov
    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready