I'm working on building a KendoGrid that has a variable number of columns that aren't known until runtime. I have code in place that takes the first row of the data and generates the schema and column information, which gets attached to the Kendo DataSource before the grid is wired up. I'm also using a proxy to inject the column field and display name into the template.
What I'm having a hard time dealing with is not knowing how to reference the row data directly, without knowing the property name. I know in a normal kendo template, you could do #= WorkItemId = to get the value itself, but I'm looking for something along the lines of #= model[item.field] # so I can pull the values dynamically.
Is this possible? I've tried this, but that points back to the values I inject with the $.proxy. I've also tried item, model, etc. but nothing seems to give me what I'm looking for.
// kendo.datasource
for (i = 0; i < columns.length; ++i) {
// add template to the cell
columns[i].template = $.proxy(
kendo.template($('#QueueTemplate_Default').html()),
{
columnName: columns[i].title,
fieldName: columns[i].field
}
);
}
// cell template
<script id="QueueTemplate_Default" type="text/x-kendo-template">
#= {{model/this/something}}[item.columnName] #
</script>
// example schema that comes back from the controller
{
"schema": {
"data": "Data",
"total": "Total",
"model": {
"id": "WorkItemId",
"field": {
"WorkItemId": {
"editable": false,
"type": "number"
},
"WorkItem": {
"editable": false,
"type": "string"
},
// edited for brevity
}
}
},
"columns": [
{
"field": "WorkItemId",
"title": "Work Item Id",
"template": null
},
{
"field": "WorkItem",
"title": "Work Item",
"template": null
},
// edited for brevity
]
}