3
votes

I'm using a Grid from Kendo UI to display a bunch of data and now I want to add InCell editing.

Since JavaScript isn't my strongest point, I can't see a solution to my following problem:

The Grid is defined as:

.Editable(e => e.Mode(GridEditMode.InCell))
.Selectable(e => e.Mode(GridSelectionMode.Single).Type(GridSelectionType.Cell))
.Events(events => events.Save("subfileSaved")

With the batch mode of the datasource set to false.

Now in my subfileSaved(e) function, I get the changed values in e.values. According to Firebug, the value of e.values is Object { Fields[2].Content="11CLS1511"}.

Question: How can I best extract both the 2 from the Fields[2].Content as well as getting the 11CLS1511?

Edit: e.values.Fields[2].Content doesn't work, see screenshot

1
What do you mean by extract both the 2 from Fields[2].Content?. I suspect Fields is an array here where 2 is the index and Content is the property of the object in that index. - NaveenBhat
@NaveenBhat I tried var tmp = e.values.Fields[2].Content, but then I get a TypeError: e.values.Fields is undefined. (And I also don't know beforehand, if my function will get a 2, 5 or whatever number below 20). Maybe it is just a simple error on my side, which will result in much forehead slapping ;-) - MilConDoin
In firebug or any other console, if you are able to see Object { Fields[2].Content="11CLS1511"} for e.values, then you wouldn't be getting this error. For safer side you can write like this - var tmp = e.values.Fields ? e.values.Fields[2] ? e.values.Fields[2].Content : null : null - NaveenBhat
@NaveenBhat So what am I doing wrong? See the screeenshot at link. - MilConDoin
It looks strange to me. Please update your question with this screenshot. - NaveenBhat

1 Answers

0
votes

Are you sure that "Fields" is a collection you can access or is it rather the enumeration of your ViewModel by Firebug?

For example, what is the Model that you grid is bound to?

If I have a grid with a model like so;

Html.Kendo().Grid<AddressListViewModel>().Name("AddressList")
          .Columns(c2 =>
                                                   {
         c2.Bound(w => w.AddressTypeId).Title("Address Type").ClientTemplate("<#= AddressTypeDisplay #>");
          c2.Bound(w => w.AddressDisplay).Title("Common Name");

..miss a few

          .Events(events => events.Save("subfileSaved"))

Then on Save I can inspect all the values such as this;

function subfileSaved(e) {
    var someValue = e.Model.AddressDisplay;

    debugger;

}

Kendo does all the hard work for you and gives you a nice named instance to read of the model and the Fields. I am just wondering if you need to access the Model and Properties explicitly but without your full grid code hard to say exactly.