Here is the situation. I have a table which contains columns of the following form: ItemTypeId, StringValue1, StringValue2, StringValue3, DecimalValue1, DecimalValue2, DecimalValue3, DateValue1, DateValue2, DateValue3, etc..etc...
Then I have a metadata table which maps certain fields to certain Item Types:
ItemTypeId: 1
FieldName: Description
FieldType: text
TargetField: StringValue1
What I want is for the declared fields to appear in the Detail Template for the Grid rows. I've tried to emulate the markup for the popup editor, and generated the following attempt at a proof of concept:
$(document).ready(function () {
$("#mainGrid").kendoGrid({
dataSource: itemSource,
toolbar: ["save"],
columns: [
{ field: "Id", title: "Id" },
{ field: "Description", title: "Description" }
],
detailTemplate: kendo.template($("#details").html()),
detailInit: detailInit,
editable: true
});
});
function detailInit(e) {
var detailRow = e.detailRow;
var container = e.detailRow.find(".k-edit-form-container");
fieldSource.fetch(function () {
fieldSource.filter({ field: "ItemTypeId", operator: "eq", value: e.data.Id });
var data = this.view();
for (var i = 0; i < data.length; i++) {
var field = data[i];
// Create Label
$("<div class='k-edit-label'><label for='" + field.TargetField + "'>" + field.FieldName + "</label>").appendTo(container);
// Create Data Entry Field
var div = $("<div />");
div.attr("data-container-for", field.TargetField);
div.attr("class", "k-edit-field");
div.appendTo(container);
if (field.FieldType == "text") {
var input = $("<input />");
input.attr("name", field.TargetField);
input.attr("type", "text");
input.attr("class", "k-input k-textbox");
input.attr("data-bind", "value:" + field.TargetField);
input.appendTo(div);
}
if (field.FieldType == "decimal") {
var input = $("<input />");
input.attr("name", field.TargetField);
input.attr("data-bind", "value:" + field.TargetField);
input.appendTo(div);
input.kendoNumericTextBox();
}
}
});
}
However the details section does not seem to end up bound to the relevant fields. It correctly lists the controls that should contain the data for each item, but it neither shows the initial value in those fields, nor does it register edited values and save them when Save Changes is clicked.
What am I doing wrong here? Is what I am attempting to do feasible with the Kendo framework?
Then I have a metadata table which maps certain fields to certain Item Types:
ItemTypeId: 1
FieldName: Description
FieldType: text
TargetField: StringValue1
What I want is for the declared fields to appear in the Detail Template for the Grid rows. I've tried to emulate the markup for the popup editor, and generated the following attempt at a proof of concept:
$(document).ready(function () {
$("#mainGrid").kendoGrid({
dataSource: itemSource,
toolbar: ["save"],
columns: [
{ field: "Id", title: "Id" },
{ field: "Description", title: "Description" }
],
detailTemplate: kendo.template($("#details").html()),
detailInit: detailInit,
editable: true
});
});
function detailInit(e) {
var detailRow = e.detailRow;
var container = e.detailRow.find(".k-edit-form-container");
fieldSource.fetch(function () {
fieldSource.filter({ field: "ItemTypeId", operator: "eq", value: e.data.Id });
var data = this.view();
for (var i = 0; i < data.length; i++) {
var field = data[i];
// Create Label
$("<div class='k-edit-label'><label for='" + field.TargetField + "'>" + field.FieldName + "</label>").appendTo(container);
// Create Data Entry Field
var div = $("<div />");
div.attr("data-container-for", field.TargetField);
div.attr("class", "k-edit-field");
div.appendTo(container);
if (field.FieldType == "text") {
var input = $("<input />");
input.attr("name", field.TargetField);
input.attr("type", "text");
input.attr("class", "k-input k-textbox");
input.attr("data-bind", "value:" + field.TargetField);
input.appendTo(div);
}
if (field.FieldType == "decimal") {
var input = $("<input />");
input.attr("name", field.TargetField);
input.attr("data-bind", "value:" + field.TargetField);
input.appendTo(div);
input.kendoNumericTextBox();
}
}
});
}
However the details section does not seem to end up bound to the relevant fields. It correctly lists the controls that should contain the data for each item, but it neither shows the initial value in those fields, nor does it register edited values and save them when Save Changes is clicked.
What am I doing wrong here? Is what I am attempting to do feasible with the Kendo framework?