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

Kendo Data.Model and datasource

2 Answers 109 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gaetano
Top achievements
Rank 1
Gaetano asked on 17 Dec 2012, 01:22 PM
Hi there,

I'm currently building a kando application and I'm wondering about the use of data.model and datasources.
I would like to map My json source to a defined js entity model.

My js model is like that:

var Impianto = kendo.data.Model.define({
    id: "IdImpianto", // the identifier of the model
    fields: {
        "IdImpianto": {
            editable: false,
            nullable: false,
            type: "Number"
        },
        "RagioneSociale": {
            type: "string"
        },
        "Alias": {
            type: "string"
        },
        "Indirizzo": {
            type: "string"
        },
        "Servizio": {
            type: "string"
        }
    }
});

var dataSource = new kendo.data.DataSource({
    schema: {
        model: Impianto
    }
});


while My json response is something like:
var myDS = [{"Alias":"customer1","IdImpianto":87792,"Indirizzo":"Milano","RagioneSociale":"customer1","Servizio":"MONITORAGGIO"},{"Alias":"customer2","IdImpianto":87793,"Indirizzo":"roma","RagioneSociale":"customer2","Servizio":"PATTUGLIAMENTO"}]


on My jquery ajax success response, I tried to assign json response to My kendo entity model in this way:
var myImpianto = new Impianto();
myImpianto.dataSource = myDS;

By the way the result is that the entity is not filled with any value;

Am I doing something wrong? Is there any way to automatically fill a custom entity with a json source?

Thanks in advance!

2 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 19 Dec 2012, 09:30 AM
Hi Fabio,

 
Basically to add the received data to the DataSource you should use the Data method and there is no need to create model instance - it is created automatically:

jQuery Ajax success:

dataSource.data(myDS)

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gaetano
Top achievements
Rank 1
answered on 19 Dec 2012, 10:54 AM
Ok that works! thanks
Tags
General Discussions
Asked by
Gaetano
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Gaetano
Top achievements
Rank 1
Share this question
or