How do I bind a single json datasource with nested arrays to different tables?

1 Answer 330 Views
DataSource JSON DataSources Report Designer (standalone) Table
yusuf
Top achievements
Rank 1
yusuf asked on 15 Dec 2021, 11:54 AM
I want to bind for example cars to one table and houses to another table. In screenshot A, I am trying to bind a table column to an array of models in the cars object, but the telerik support designer doesn't allow me to see the models and select it. All is shows that its a system.Object. Am I doing something wrong? I am using a json data source like this (I am aware that the json is in single quotes, that's not a problem. I have using json data with double quotes and still the same problem):
JsonDataSource:
{
  'name': 'john',
  'age': 146,
  'cars': [{
    'model': 'Ford89',
    'price': 50
  },{
    'model': 'BMW',
    'price': 42
  }],
  'houses': [{
    'location': 'los angelos',
    'cost': 505
  },{
    'location': 'sunny town',
    'cost': 505
  }]
}

1 Answer, 1 is accepted

Sort by
1
Todor
Telerik team
answered on 20 Dec 2021, 08:38 AM

Hello Yusuf,

Indeed, the DataSource wizards cannot dig into the internal properties of the array items. For that reason, the "model"/"price" of the "cars" and "location"/"cost" of "houses" are not listed in the wizard. The reason is that generally, the array items have to be displayed in another data item.

The approach that I suggest is to use Bindings to set the DataSource for the dedicated tables that are going to display the "cars" and "houses" to the corresponding main DataSource fields, for example, "=Fields.cars". Inside the tables, you need to type manually the inner properties names in the columns they are to be displayed in, for example, "=Fields.model" for the "cars". In run-time, the Reporting engine will assign the "cars" array as a DataSource for the table and resolve and display its properties properly in the table.

Regards,
Todor
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Tags
DataSource JSON DataSources Report Designer (standalone) Table
Asked by
yusuf
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or