I have a DataSource object that uses a schema model to extract the pertinent info out of an XML document:
The grid is
When I click on "New Thing" a new empty row does not appear in the table, and the html developer console shows
Uncaught ReferenceError: timestamp is not defined
The apparent issue is that kendo.data.xml loads up data records with this statement
record[field] = modelInstance._parse(field, model.fields[field].field(value));
In other words, the field property of a models fields is expected to be a function
and when kendoGrid handles "New Thing" it calls addRow which makes a default row via dataSource.insert, which in turn relies on a new instance of the xml reader model, which in turn relies on properly defined defaults.
Unfortunately the Model.define function uses the field property of a models fields as a key for associating with a default value
In the case of XML, name is an anonymous function because field.field is taking precedence over name.
A guess is that Model.define should contain this:
name = typeof(field.field)=='string' ? field.field : name;
var dataSource1 = new kendo.data.DataSource ({transport: { read: { cache: false, url: crud, data: { action: 'list' }, error: successCheck }, update: { cache: false, url: crud, data: { action: 'update' }, success: successCheck }, destroy: { cache: false, url: crud, data: { action: 'delete' }, success: successCheck }, create: { cache: false, url: crud, data: { action: 'create' }, success: successCheck }},schema: { type: 'xml', data: '/TABLE/THINGS', model: { id: "thingid", fields: { thingid: { editable:false, field: "id/text()" }, name: { editable:true, field: "name/text()" }, timestamp: { editable:false, field: "timestamp/text()" } } } }}
The grid is
$("#thingList").kendoGrid({ dataSource: dataSource1, pageable: true, toolbar: [ { name:"create", text:"New Thing", id:"add"}], columns: [ { field: "name", title: "Name", template: "<a class='viewlink' href='viewthing?id=${thingid}'>${name}</a>" }, { field: "timestamp", title: "Created", width: "12em" }, { command: [ {name:"edit",text:"Rename"}, "destroy"], title:" ", width:"15.5em"} ], editable: "inline"});When I click on "New Thing" a new empty row does not appear in the table, and the html developer console shows
Uncaught ReferenceError: timestamp is not defined
The apparent issue is that kendo.data.xml loads up data records with this statement
record[field] = modelInstance._parse(field, model.fields[field].field(value));
In other words, the field property of a models fields is expected to be a function
and when kendoGrid handles "New Thing" it calls addRow which makes a default row via dataSource.insert, which in turn relies on a new instance of the xml reader model, which in turn relies on properly defined defaults.
Unfortunately the Model.define function uses the field property of a models fields as a key for associating with a default value
name = field.field || name;
if (!field.nullable) {
value = proto.defaults[name] = field.defaultValue !== undefined ? field.defaultValue : defaultValues[type.toLowerCase()];
}
In the case of XML, name is an anonymous function because field.field is taking precedence over name.
A guess is that Model.define should contain this:
name = typeof(field.field)=='string' ? field.field : name;