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

[Solved] Editable:false not working with complex model

3 Answers 572 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 13 Mar 2015, 03:53 PM
I have a grid with most cells bound to model members at the first level. However, my model also contains object members, and I am binding a few columns to members within the object. I am using incell editing, but I obviously want to restrict editing on certain fields. 

Here is an small example of my model:
{
   Id: 123456,
   Name: 'some name',
   Cost: 34.56,
   Station: {
      CallLetters: 'WKGB',
      NetworkId: 123
   }
}

I am able to bind to the grid without any issue using the following:
schema: {
   model: {
      fields: {
         Id: { type: "number", editable: false },
         Name: { type: "string" },
         Cost: { type: "number" },
         Station: { CallLetters: { type: "string", editable: false }, editable: false }
      }
   }
}

and:
columns = [
   { title: 'Id', field: 'Id', hidden: true, menu: false },
   { title: 'Station', field: 'Station.CallLetters', width: 80 },
   { title: 'Name', field: 'Name', width: 120 },
   { title: 'Cost', field: 'Cost', width: 95, format: '0:c2' }
]

As you can see, I am setting (and trying to set) certain fields editable: false, and this works just fine for the Id field, and any other field at the top level of my model, but it does not work for the Station.CallLetters field. The Station column is still editable.
Everything else is working fine.

Anyone know what I am doing wrong?

3 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 16 Mar 2015, 05:31 PM
I have pretty much figured this out by using a template and eliminating the field: 'Station.CallLetters' attribute of the column definition.

var stationContent = kendo.template('${Station.CallLetters} ');

and

{ title: hbLocalization.getString($scope.stringsModule, "_Station_"), template: stationContent, width: 80, hidden: !$scope.model.isMultiStation },

Was hoping to find a better way to do this, but haven't yet.
0
Alexander Popov
Telerik team
answered on 17 Mar 2015, 01:26 PM
Hi David,

This can be done by specifying the editable options in a separate model field, which explicitly refers to the nested property. For example: 
"Station.CallLetters": { editable: false },

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
David
Top achievements
Rank 1
answered on 17 Mar 2015, 05:46 PM
Excellent! Thank you. Not sure why I didn't try that meself.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Alexander Popov
Telerik team
Share this question
or