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

grid foreign key datasource instead of list/array

2 Answers 333 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jye
Top achievements
Rank 1
Jye asked on 13 Jul 2012, 07:49 AM

I'm pretty new to kendo and Im trying to set up a foreign key in a grid but instead of using a list like in the example im attempting to use a second datasource instead.
At the moment when in edit mode i can select a drop down box which shows the text values of the foreign key instead of the id number but after i switch out of edit mode it reverts back to an id.

This is currently what i have
http://jsfiddle.net/QPXrf/8/ 

I'm just needing some direction in what would be the best way to do this.




2 Answers, 1 is accepted

Sort by
0
Jye
Top achievements
Rank 1
answered on 14 Jul 2012, 02:11 PM
ok im pretty much worked this out, but im not sure how this will work with update.
what did was use a function and template.

This forum post was very helpful in getting it working. 
http://www.kendoui.com/forums/ui/grid/custom-editor---small-issue.aspx 

For the template (inside the grid when setting column fields)
{field: "ticketopener", 
                      template: " #= getName(ticketopener)   # ",
                        values: staff, 
                        editor: staffEditor},

and the function
function getName(id) {
for (var i = 0; i < staff._view.length; i++) {
if (id == staff._view[i].value ) {
return staff._view[i].text;
}
}
}

here is an update version of the jsfiddle
http://jsfiddle.net/7bZGm/ 

Next step is to make that function more generic 
0
Jye
Top achievements
Rank 1
answered on 15 Jul 2012, 02:42 AM
and here's a more generic function

function getName(id, dsource, intfield, textfield 
) {
for (var i = 0; i < dsource._view.length; i++) {
if (id == dsource._view[i][intfield] ) {
return dsource._view[i][textfield]
}
}
Tags
Grid
Asked by
Jye
Top achievements
Rank 1
Answers by
Jye
Top achievements
Rank 1
Share this question
or