Nesting formats in KendoGrid Column


#1

I’m populating a KendoGrid column by joining two fields from an ExactDimension (value and unit.id). However, when the unit.id is ‘therm’ it doesn’t make sense in the UI, since it should really show ‘therms’. Why isn’t the following working? I’m still getting ‘therm’ in the UI.

                {
                    "id": "consumption",
                    "label": "{~EnergyManagement.Account.BillingAccountSummaryKendoGrid.consumption~}",
                    "field": "consumption",
                    "format": {
                        "funk": "joinFields",
                        "record": true,
                        "args": [
                            {
                                "field": "consumption.value",
                                "format": "default"
                            },
                            {
                                "field": "consumption.unit.id",
                                "format": {
                                    "funk": "applyItemConditions",
                                    "args": [
                                        {
                                            "comparator": "==",
                                            "comparisonValue": "therm",
                                            "conditionalValue": "therms"
                                        }
                                    ]
                                }
                            }
                        ]
                    },
                    "align": "left",
                    "sortable": true
                },

#2

Either something was wrong with my environment, or this helped for some reason. I saw another implementation that had extra brackets around “args”. So this works:

                {
                    "id": "consumption",
                    "label": "{~EnergyManagement.Account.BillingAccountSummaryKendoGrid.consumption~}",
                    "field": "consumption_EMUI",
                    "format": {
                        "funk": "joinFields",
                        "record": true,
                        "args": [[
                            {
                                "field": "consumption_EMUI.value",
                                "format": "default"
                            },
                            {
                                "field": "consumption_EMUI.unit.id",
                                "format": {
                                    "funk": "applyItemConditions",
                                    "args": [[
                                        {
                                            "comparator": "==",
                                            "comparisonValue": "therm",
                                            "conditionalValue": "therms"
                                        }
                                    ]]
                                }
                            }
                        ]]
                    },
                    "align": "left",
                    "sortable": true
                },

#3

Yes that makes sense, because args should be an array of arguments to the format function specified. In this case, those format functions are joinFields and applyItemConditions, and the first (non-value) argument to each of these functions is an array.

Taking joinFields as an example, here is the function signature:

function joinFields(item, fields, joiner, labels, notCompact) { /* ... */ }

If you wanted to also provide a joiner argument set to " unit: ", the configuration would look like this:

{
  "id": "consumption",
  "label": "{~EnergyManagement.Account.BillingAccountSummaryKendoGrid.consumption~}",
  "field": "consumption_EMUI",
  "format": {
    "funk": "joinFields",
    "record": true,
    "args": [
      [
        {
          "field": "consumption_EMUI.value",
          "format": "default"
        },
        {
          "field": "consumption_EMUI.unit.id",
          "format": {
            "funk": "applyItemConditions",
            "args": [
              [
                {
                  "comparator": "==",
                  "comparisonValue": "therm",
                  "conditionalValue": "therms"
                }
              ]
            ]
          }
        }
      ],
      " unit: "
    ]
  },
  "align": "left",
  "sortable": true
}

NB: the first argument (item in the case of joinFields) is passed automatically by the framework, the 2nd argument onward are configured.