Combine datasources to populate the columns of a KendoGrid

#1

In a page, I’ve two components:

  • A KendoGrid component that uses a DataSource which basically call a fetch on a target type (i.e. TargetType.fetch(...)).
  • A chart.MetricsHistogram component that uses a DataSource which basically call a getDistribution on a target type (i.e. TargetType.getDistribution(...)).

As I have too many instances of TargetType, for some of them the label (which is the name field) in MetricsHistogram does not show up. So we are thinking to add another column in the KendoGrid to hold the value shown in the histogram.

How could we achieve this, Is it possible to use multiple datasource to populate the columns of a KendoGrid?

0 Likes

Fetch data in a custom function
#2

Try childDataSources on a DataSource(childDataSources is a Loadable class property).

1 Like

#3

example

main data source

ui module MyModule {
    dataSource MyDataSource {
        "collection": true,
        "c3type": "Person",
        "c3function": "fetch",
        "c3arguments": {
            "spec": {
                "include": "field1, field2, field3",
                "limit": -1
            }
        },
        "cache": false,
        "responseSelector": "objs",
        "childDataSources": [
          {
              "sourceDataSource": "MyModule.ChildDataSource",
              "sourceMapping": {
                  "from": {
                      "field": "field1"
                  },
                  "to": "field1.id"
              },
              "targetMappings": [
                  {
                      "from": "id",
                      "to": "childType"
                  }
              ]
          }
      ]
    }
}

child data source

ui module MyModule {
    dataSource ChildDataSource {
        "collection": true,
        "c3type": "ChildType",
        "c3function": "fetch",
        "c3arguments": {
            "spec": {
                "include": "field1",
                "limit": -1
            }
        },
        "cache": false,
        "responseSelector": "objs"
    }
}
2 Likes

#4

thanks for the hint, I’ve end up using targetMappings clause with custom mappingHelper function, but for some reasons the function is called twice!

"facilitiesDataSourceGrid": {
  "collection": true,
  "autoLoad": false,
  "c3type": "Facility",
  "responseSelector": "objs",
  "c3arguments": {
    "spec": {
      "filter": "!exists(parent)",
      "include": "[id, name, address1, city, province, postal_code, buildingSizeAnswer, buildingNameAnswer, metricResult, ranking]",
      "limit": 25
    }
  },
  "childDataSources": [
    {
      "sourceDataSource": "histogramDataSource",
      "sourceMapping": {
        "from": {
          "field": "id"
        },
        "to": "id",
        "mappingHelper": "histogramEvaluationResultFetch"
      },
      "targetMappings": [
        {
          "from": "id",
          "to": "metricResult",
          "mappingHelper": "mapHistogramEvaluationResultToMetricResult"
        },
        {
          "from": "id",
          "to": "ranking",
          "mappingHelper": "mapHistogramEvaluationResultToRanking"
        }
      ]
    }
  ]
},
0 Likes