I am new to Kendo Web widget. I have two different data entities to render rows for one grid, which are bound to the same service.
Can I use multiple datasources for one single grid?
If it is possible, could you give me an example how to make it? Or alternative solutions ?
Guillermo Sanchez
3 Answers, 1 is accepted
The Kendo UI grid can have only one data source.
There are two ways to bind the grid to multiple entities:
1. Create a single JavaScript array which contains both types of entities. Bind the grid to that array.
2. Create a remote service which returns both types of entities in the same response. Bind the grid to that service.
The documentation of the data source shows how to configure the grid for local (array) or remote service binding.
Atanas Korchev
the Telerik team
For some reason, The remote services cannot return both data entities in the same reponse. The followings are how they look like separately.
Customer:{
"$descriptor": "customers",
"$totalResults": 22,
"$startIndex": 1,
"$itemsPerPage": 100,
"$resources": [
....
{
"$key": "5ca0f969-633c-4d51-a29b-b5df68b6b58e",
"$descriptor": "",
"Name": "Sample Company",
"CreatedOn": "\/Date(1365718827000+0000)\/",
"UpdatedOn": "\/Date(1365718827000+0000)\/",
"CustomerPrimaries": {
"$resources": [
{
"$key": "dff69f34-4c55-466b-92fc-237762d5b533",
"TenantId": "7b6791d5-8658-44e5-86bc-8181735d0bf7",
"Type": "BillingAndPayments",
"CreatedOn": "\/Date(1365718828000+0000)\/",
"UpdatedOn": "\/Date(1365718828000+0000)\/",
"Customer": {
"$key": "5ca0f969-633c-4d51-a29b-b5df68b6b58e"
},
"Contact": {
"$key": "18441e96-cf6f-4bc2-9ef9-6c2351992cf5"
},
"Address": {
"$key": "cde2839b-66de-4c0d-b48b-68ee72a85faa"
}
}
]
}
},
]
}
///////////////////////////////////////////////////////////////////////////////////////////
CustomerPrimaries:
{
"$descriptor": "customerPrimaries",
"$totalResults": 1,
"$startIndex": 1,
"$itemsPerPage": 100,
"$resources": [
{
"$key": "dff69f34-4c55-466b-92fc-237762d5b533",
"$descriptor": "",
"TenantId": "7b6791d5-8658-44e5-86bc-8181735d0bf7",
"Type": "BillingAndPayments",
"CreatedOn": "\/Date(1365718828000+0000)\/",
"UpdatedOn": "\/Date(1365718828000+0000)\/",
"Customer": {
"$key": "5ca0f969-633c-4d51-a29b-b5df68b6b58e"
},
"Contact": {
"$key": "18441e96-cf6f-4bc2-9ef9-6c2351992cf5",
"TenantId": "7b6791d5-8658-44e5-86bc-8181735d0bf7",
"FirstName": "Bob",
"LastName": "Loblaw",
"Title": "Director",
"PhoneMobile": "866-555-6325",
"PhoneWork": "866-555-6325",
"PhoneHome": "866-555-6325",
"EmailWork": "bloblaw@abc.com",
"EmailPersonal": "bloblaw@abc.com",
"URL": null,
"ExternalId": "1",
"ExternalReference": null,
"CreatedOn": "\/Date(1365718827000+0000)\/",
"UpdatedOn": "\/Date(1365718827000+0000)\/",
"Customer": {
"$key": "5ca0f969-633c-4d51-a29b-b5df68b6b58e"
},
"Addresses": {}
},
"Address": {
"$key": "cde2839b-66de-4c0d-b48b-68ee72a85faa",
"TenantId": "7b6791d5-8658-44e5-86bc-8181735d0bf7",
"Name": "Test",
"Type": "Billing",
"Street1": "Test",
"Street2": "Test",
"Street3": null,
"Street4": null,
"City": "Test",
"StateProvince": "Test",
"PostalCode": "Test",
"Country": "USA",
"Phone": "Test",
"Email": "Test",
"URL": null,
"ExternalId": null,
"ExternalReference": null,
"CreatedOn": "\/Date(1365718828000+0000)\/",
"UpdatedOn": "\/Date(1365718828000+0000)\/",
"Customer": {
"$key": "5ca0f969-633c-4d51-a29b-b5df68b6b58e"
},
"Contact": {
"$key": "18441e96-cf6f-4bc2-9ef9-6c2351992cf5"
}
}
}
]
}\
I want to render rows of "Name" from Customer entity response, "FirstName" from CustomerPrimaries's Contact and
"Street1" from CustomerPrimaries's in the same grid. I wonder how kendo grid handle this issue?
Thanks,
As I said in my previous response the Kendo Grid cannot have more than one data source. If case you cannot modify your service you can go with option 1:
1. Create a single JavaScript array which contains both types of entities. Bind the grid to that array.
We however cannot assist with merging the entities in a JavaScript array. This is specific business logic which isn't related to Kendo UI.
Atanas Korchev
the Telerik team