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

Date time in Kendo Grid

1 Answer 860 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 16 Oct 2012, 03:48 PM
Hello I am using Kendo grid to edit price lists.

I am trying to edit single value in table:

@(Html.Kendo().Grid(Model).Name("PriceList")
    .Columns(columns =>
    {
        columns.Bound(p => p.Id).Hidden();
        columns.Bound(p => p.Name);
        columns.Bound(p => p.ValidFrom).Format("{0:dd.MM.yyyy h:mm:ss}");
        columns.Bound(p => p.ValidTill).Format("{0:dd.MM.yyyy h:mm:ss}");
        columns.Bound(p => p.Created).Format("{0:dd.MM.yyyy h:mm:ss}");
        columns.Bound(p => p.UserName);
        columns.Bound(p => p.FilePath);
        columns.Command(command => { command.Edit(); command.Destroy(); });
    })
    .DataSource(dataSource => dataSource.Ajax()
            .Model(model =>
            {
                model.Id(p => p.Id);
                model.Field(p => p.ValidFrom).Editable(false);
                model.Field(p => p.ValidTill).Editable(true);
                model.Field(p => p.Created).Editable(false);
                model.Field(p => p.UserName).Editable(false);
                model.Field(p => p.FilePath).Editable(false);
                model.Field(p => p.Name).Editable(false);
        })
        .Read("PriceList_Read", "Admin")       
        .Destroy("PriceList_Editing_Destroy", "Admin")
        .Update(update=>update.Action("PriceList_Editing_Update", "Admin"))
        .Events(e=>e.Error("error_handler"))
    )   
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .AutoBind(true)
)

And I am having troubles passing edited value in grid to my controller:

public ActionResult PriceList_Editing_Update([DataSourceRequest] DataSourceRequest request, PriceListViewModel model)
        {
             
                    int Id = model.Id;
                    string Name = model.Name;
                    DateTime date = model.ValidTill; // 0001 00:00:00 value all the time
          
            return View("Index", GetViewResult());
        }

I am always getting back empty datetime value (by empty I mean {1. 1. 0001 0:00:00}) same problem is with 2 other columns using DateTime property (Created and ValidFrom). Rest of the values are posted back correctly. I was trying to get those values using string DateTillStr = Request.Params["ValidTill"]; but if I check my GET in firebug I can see grid is not sending back this value inside Request it sends only NON Datetime values of my model object. Like this:

Actual  false
FilePath    D:\Projects\CPSkla\CPSkla\App_Data\Cen°k 2012_10.xlsx
Id  23
Name    Testovací ceník
User    0
User1   null
UserName    djezek

Nothing more nothing less, only these 7 attributes I am missing rest 4 from my model:

public partial class PriceListView
    {
        public int Id { get; set; }
        public int User { get; set; }
        public string Name { get; set; }
        public System.DateTime ValidFrom { get; set; }
        public System.DateTime ValidTill { get; set; }
        public string FilePath { get; set; }
        public Nullable<System.DateTime> Created { get; set; }
        public Nullable<System.DateTime> Updated { get; set; }
        public bool Actual { get; set; }
        public string UserName { get; set; }
    }


Is there some other way to post these data back? I figured out I can attach additional data to Update request but I had an issue how to identify edited row in the table in javascript function (I know how to identify selected value but not edited).

Please help me I am quite desperate.

David Ježek

1 Answer, 1 is accepted

Sort by
0
ANDREW REED
Top achievements
Rank 1
answered on 18 Oct 2012, 09:03 AM
Having exactly the same issue, but mine is on the Create method.

I am using Codefirst and if I change this to a string from datetime, it appears in the Get to the Controller. If its a datetime, the KendoUI grid does not add it to the querystring.

When TestDate is set to DateTime in my model:

http://localhost:53921/Test/Create?ID=0&ID=0&Detail=fgdfgdfgdfgdf&UserProviderKey=

When TestDate is set to string
http://localhost:53921/Test/Create?ID=0&ID=0&Detail=fgdfgdfgdfgdf&TestDate=dkflsd&UserProviderKey=

Since I also have a default value of today in the KendoUI.Grid Model, I'm starting to think either we are missing some element or this is a bug.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
ANDREW REED
Top achievements
Rank 1
Share this question
or