Add compound metric into KendoGrid

#1

In a KendoGrid in my UI I am attempting to add a compound metric into a column. For this I add the following 2 sets of code but the field was unsuccessfully populated. The metric works in the console.

Do I have an error in one or both sets of code I am trying or is there another method I need to use to apply the latest value from a metric into the Grid?

                    "id": "columnA",
                    "field": "columnA",
                    "align": "center",
                    "label": "{~PredictiveMaintenance.columnA.Text~}",
                    "sortable": true,
                    "data": {
                        "c3type": "Type",
                        "c3function": "evalMetric",
                        "c3arguments": {
                            "spec": {
                                "id": "{{params.id}}",
                                "expression": "CompoundMetric"
                            }
                        }
                    }

or

                    "id": "columnA",
                    "field": "columnA",
                    "align": "center",
                    "label": "{~PredictiveMaintenance.columnA.Text~}",
                    "sortable": true,
                    "data": {
                        "record": {
                            "record": true,
                            "collection": false,
                            "c3type": "Type",
                            "c3function": "evalMetric",
                            "c3arguments": {
                                "spec": {
                                    "id": "{{params.id}}",
                                    "expression": "CompoundMetric",
                                    "start":"2018-02-15T00:00:00",  **also tried one with a createDynamicDate
                                    "end":"2018-02-17T00:00:00",  **also tried one with a createDynamicDate
                                    "interval": "DAY"
                                }
                            },
                            "responseSelector": "data",
                            "responseTransfrom": {
                                "firstItem": true
                            }
                        }
                    }
0 Likes

#2

I don’t think KendoGrid component supports specifying data source for each column.

What you could do is to specify data source on KendoGrid component level, and use field to specify the field for the column. For example,

            {
                "id": "myGrid",
                "component": "KendoGrid",
                "renderTo": "#myGrid",
                "data": {
                    "collection": {
                        "collection": true,
                        "c3type": "myType",
                        "c3function": "fetch",
                        "responseSelector": "objs",
                        "c3arguments": {
                        "spec": {
                            "include": "fieldA, fieldB"
                         }
                      }
                   }
                },
                "columns": [
                    {
                        "label": "My Label A",
                        "field": "fieldA"
                    },
                    {
                        "label": "My Label B",
                        "field": "fieldB"
                    }
                ]
            }
0 Likes

#3

Is there a way to do this using multiple metrics without stored calculations on the main type? I’m trying to avoid increasing the already significantly large amount of stored calcs on a single type.

0 Likes

#4

You need to implement your own transform function.

In the data source, you could call evalMetrics with multiple metrics, and specify customResponseTransforms to be your own transform function. For example,

{
        "collection": true,
        "record": false,
        "c3type": "myType",
        "c3function": "evalMetrics",
        "responseSelector": "",
        "customResponseTransforms": [
            {
                "transform": "myCustomTransform"
            }
        ]
}

In your myCustomTransform transform function, you could transform evalMetrics result data to the shape that KendoGrid could consume.

C3.define("C3.transform.myCustomTransform", {
    extend: "C3.transform.Transform",

    /**
     * @inheritdoc
     */
    dataTransform: function(data) {
        var new_data = transformData(data); // transformData is a function that you should implement
        
        return new_data;
    }
});
0 Likes

#5

Okay, that makes sense

Can I use 2 data sources on the KendoGrid? I also will need to do a fetch from the same type for other details required for the filter and other fields on the KendoGrid

0 Likes

#6

If those details belong to same grid, they have to belong to same data source.

KendoGrid also supports detailGrid, like https://demos.telerik.com/kendo-ui/grid/detailtemplate, and we could specify separate data source for detailGrid, like below,

{
        "component": "KendoGrid",
        "data": {
            "collection": "myCollection",
            "detailCollection": "myDetailCollection"
        }
}

You may also specify parentField and detailField to link match detail grid to parent grid. Documentation for parentField and detailField could be found at https://your-env.c3-e.com/assets/docs/output/index.html#!/api/C3.view.KendoGrid

0 Likes