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

Multiple datasources for one grid

3 Answers 658 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Guillermo
Top achievements
Rank 1
Guillermo asked on 18 Apr 2013, 05:13 AM
Good day,

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

Sort by
0
Atanas Korchev
Telerik team
answered on 18 Apr 2013, 12:25 PM
Hi,

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.

Regards,
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!
0
Guillermo
Top achievements
Rank 1
answered on 18 Apr 2013, 09:19 PM
Thanks for your quick reply, and appreciate your suggesed solutions.To make my case more in details: I have two data entities response "Customer" and "CustomerPrimaries". and "CustomerPrimaries" is reference field from "Customer" with Key.

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,
0
Atanas Korchev
Telerik team
answered on 19 Apr 2013, 07:48 AM
Hello,

 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.

Regards,
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
Guillermo
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Guillermo
Top achievements
Rank 1
Share this question
or