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

Best way to implement cross-referenced field customization?

2 Answers 9 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sebastian
Top achievements
Rank 1
Sebastian asked on 27 Jul 2015, 09:14 AM

Hi,

if I use a template to customize a kendo grid data entry, I can pass a key as a parameter to a js function. In this way I can customize the behaviour of the function depending on other keys in the model field (=table row).

Just a nonsense example to show what I mean:

Let's say we have the data

[{ id: 1, name: "foo" }]

and the model

{ id: "id", fields: {"foo": {type: "String"},"id": {type: "Number"}}

then I can write into the "foo" column template key

kendoGrid({ columns: [{field: "foo", template: "#=getID(id)#"}] })

which references to the js function

function getID(id) { return "<b>"+id+"</b>" }

 

I'm a bit suprised that this works (has somebody an explanation why the template can access the id key of the data)? I'm quite new to js...), but it does and is quite helpful for me.

Now to the topic: I'd like to to customize the editor - a dropdownlist like in the example http://demos.telerik.com/kendo-ui/grid/editing-custom. But the content of this dropdownlist should change according to the data. Is there a way to pass the value of a key to the editor function in a similar way like in the template example above?

function dropDownListEditor(container,options,id) {

[...]

kendoDropDownList({dataSource: {data: dropdowncontent[id]}}))

[...] 
}

 As I have understood the editor function has the predefined parameters container+options, are these fixed or somehow extendable? Which is the best way to implement such a behaviour?

 

Thanks in advance!

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 29 Jul 2015, 07:38 AM

Hello Sebastian,

 

To your questions:

1. In the template you have reference to the whole model for the row. That said if the model is of shape `{ id: "id", fields: {"foo": {type: "String"},"id": {type: "Number"}}` you can reference any property of this model regardless of the column. Its up to the developer to decide how the template should look.

 

2. I'm not quite sure what you mean for the editor template. In the editor function(container, options) you have reference to the actual model to be edited - options.model. I guess that is what you need.

 

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Sebastian
Top achievements
Rank 1
answered on 29 Jul 2015, 08:09 AM
Aaaah, looks good. That seems to be the thing I need. I will give it a try.
Tags
Grid
Asked by
Sebastian
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Sebastian
Top achievements
Rank 1
Share this question
or