kendo-ui grid foreign key column and mvvm -
i struggling kendo-ui grid foreign key column , mvvm
i able combine "foreign key column" example "mvvm" example
my question is: "how data-bind values property of look-up field?"
so kind of older post, had work around same issue , found while trying solve. figured i'd answer question posterity.
the "values" property doesn't seem work 100% in kendo grid in mvvm. have worked around in 2 step process.
- tack "this.viewmodel" (where "viewmodel" whatever calling vm) in front of "loggerseverityvalues". give dropdownlist when editing field.
- utilize template functionality display correct value in grid. use little function make easier:
gettext: function (matchvalue, valuesarray, text, value) { if (text === undefined) { text = 'text'; } if (value === undefined) { value = 'value'; } var rettext = "no value found"; finalarr = $.grep(valuesarray, function (val, integer) { return val[value] == matchvalue; }); if (finalarr.length > 0) { rettext = finalarr[0].text; } return rettext; }
the final of field along lines of this:
{ field: 'severity', width: 270, values: this.viewmodel.loggerseverityvalues, template: '#: gettext(severity, this.viewmodel.loggerseverityvalues) #' }
note gettext() function can override text , value parameters if need to.
anyway worked me. kind of workaround, of release 2014.3.1411 anyway doesn't appear kendo mvvm bindings work foreign keys.
edit:
for using kendo ng2+ components, same pattern pipe transform works.
pipe:
import { pipe, pipetransform } '@angular/core'; @pipe({ name: 'gettext' }) export class gettextpipe implements pipetransform { transform(value: any, idpropertyname: string, valuepropertyname: string, valuearray: any[]): { if (value != null && valuearray != undefined) { let retindex = valuearray.map(v => v[idpropertyname]).indexof(value); return valuearray[retindex][valuepropertyname]; } else { return ''; } } }
usage:
<kendo-grid-column field="severity" title="severity" width="150px"> <template kendogridcelltemplate let-dataitem="dataitem"> {{dataitem.severity | gettext:'severity':'severityname':loggerseverityvalues}} </template> </kendo-grid-column>
Comments
Post a Comment