Setting a column default value in the kendo ui grid to DateTime.Now

Viewed 4026

I wish to make a grid within my visual studio program to display DateTime.now as a default but it's not working.

The column within the Kendo grid:

columns.Bound(c => c.CurrentDate).EditorTemplateName("Date").Format("{0:dd/MM/yy}");

The declaration within my model:

public DateTime CurrentDate { get; set; }

When I load the web page the value of the text box within the column is set to the current date but the value is not displayed.

My Kendo UI Grid Code:

@(Html.Kendo().Grid<Kendo_UI_Bootstrap_Integration.Models.EID>()
        .Name("EIDGrid")
        .Columns(
            columns =>
            {

                columns.Bound(c => c.Breed);
                columns.Bound(c => c.Gender);
                columns.Bound(c => c.AnimalId);
                columns.Bound(c => c.EIDDate).EditorTemplateName("Date").ClientTemplate(DateTime.Now.ToString("dd/MM/yy"));//.ClientTemplate(DateTime.Now.ToString()).Format("{0:dd/MM/yy}").EditorTemplateName("Date");//.EditorTemplateName("Date")
                columns.Bound(c => c.EIDNum);
                columns.Bound(c => c.BatchNum);
            }
    )
    .Scrollable(s => s.Height("350px"))
    .Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
    .Pageable()
    .DataSource(datasource => datasource
        .Ajax()
        .Model(model =>
        {
            model.Id(p => p.SireGuid);
            //model.Field(p => p.SireGuid).DefaultValue(Guid.Empty);
            //model.Id(p => p.EIDDate);
            //model.Field(p => p.EIDDate).Editable(true);

        })
        .PageSize(100)
        .Batch(true)
        .Sort(s => s.Add("Name"))
    ) )

My Model code:

using System; 
using System.Collections.Generic; 
using System.Globalization; 
using System.Linq; 
using System.Web;

namespace Kendo_UI_Bootstrap_Integration.Models {
   
    public class EID
    {

        public string Breed { get; set; }
        public string Gender { get; set; }
        public string AnimalId { get; set; }
        public int EIDNum { get; set; }
        public int BatchNum { get; set; }

        public DateTime EIDDate { get; set; }
        

        
       
        public int ClusterIndex
        {
            get; set;
        }
        public System.Guid SireGuid { get; set; }
    }
 }

My Controller Code:

using System;
using System.Collections.Generic;
using System.Linq; using System.Web; 
using System.Web.Mvc;

namespace Kendo_UI_Bootstrap_Integration.Controllers {
    public class EidController : Controller
    {
        // GET: Eid
        public ActionResult EidView ()
        {
            return View();
        }
    }
}
1 Answers
Related