Date formatting in Grid

2 Answers 3494 Views
Grid
Lars
Top achievements
Rank 1
Lars asked on 09 Feb 2016, 02:07 PM

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 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 11 Feb 2016, 12:40 PM

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
Lars
Top achievements
Rank 1
commented on 11 Feb 2016, 12:48 PM

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

0
Boyan Dimitrov
Telerik team
answered on 15 Feb 2016, 09:41 AM

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
Tags
Grid
Asked by
Lars
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or