Concatenating two fields from the data source into a single KendoGrid Column

#1

What would be the best way to concatenate two fields together in a field for column on the c3ui page? I have tried using the concat function in the field (e.g. “field”: “concat(cells[9].str, cells[0].str)”) and no result appears. Ideally this field would produce an output of the cell value then a ‘/’, then the second field value (e.g. path/filename.csv).

0 Likes

#2

Thanks for posting this here, Todd, after our conversation. I’ll put a bit more context here for other digesters of this discussion and then compose an answer in a subsequent post.

We are working with a KendoGrid here, and we are trying to populate a single column in that KendoGrid with the concatenation of two fields that are returned correctly in our data model (cells[9].str and cells[0].str both return valid strings when projected in their own, independent KendoGrid columns.

0 Likes

#3

in your column definition: use args array and set the funk

"format": {
                  "funk": “getMySpecialCell”,
                  "record" : true,
                  "args": [
                      [{
                          “field1Column”: “field1Column”,
                          "field2Column": "field2Column"
                      }]
                  ]
              }

In ui/content/js/customCode/{ProjectName}Helpers.js add

(function() {
var helpers = C3.script.helpers;
  getMySpecialCell: function(item, fields){
         var field1 = C3.util.getDescendantProp(item, fields[0].field1Column);
         var field2 = C3.util.getDescendantProp(item, fields[0].field2Column);
         return field1 + " " + field2;
 }
})();
1 Like

#4

Use the joinFields helper function as your formatter:

{
    "id": "dimensions",
    "field": "length",
    "format": {
        "funk": "joinFields",
        "record": true,
        "args": [
            [
                "length",
                "width"
            ],
            " x "
        ]
    }
}

Just make sure both fields are included in your data source.

1 Like

#5

That looks like a useful funk. Where is joinFields defined and what other ones are available?

0 Likes

#6

With the UI documentation:
https://<environment_url>/assets/docs/output/index.html#!/api/C3.script.helpers

2 Likes

closed #7
0 Likes