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

Problem with XML dataSource and inline editing

1 Answer 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 21 May 2012, 10:26 AM
I have a DataSource object that uses a schema model to extract the pertinent info out of an XML document:

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; 




1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 May 2012, 02:54 PM
Hello Richard,

 Thank you for reporting this problem. I have landed a fix which should appear with the next official release. If you need this earlier please open a support ticket and I will send it to you.

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or