Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid how to have multiple columns in one

Tags:

kendo-ui

I am trying to append two columns bound into one kendo grid column. Below doesn't seem to work.

var grid = $("#grid").kendoGrid({
                dataSource: { data: SomeData },
                columns: [{
                    field: "Column1" + "Column2"
                }]

            }).data("kendoGrid");
like image 276
desiguy Avatar asked Jan 17 '13 19:01

desiguy


2 Answers

If you do not need to edit the cell you can do what is known as composed cells or composition and it is implemented using KendoUI template. (Try googling for "kendoui grid with composed cells").

Example

var leitmotifs = [
    { 
        company: "OnaBai", 
        leitmotif: "Working on a cloud of documents!" 
    },
    { 
        company: "Nike", 
        leitmotif: "Just do it!" 
    }
];

var grid = $("#table").kendoGrid({
    dataSource: {
        data: leitmotifs
    },
    columns   : [
        { 
            title: "Company", 
            template: "#= company + ' : ' + leitmotif #"
        }
    ]
});
like image 50
OnaBai Avatar answered Oct 03 '22 23:10

OnaBai


Did you have a look at the schema.parse method on the DataSource? You can add up columns there as new fields with no issues. Then the field would be available when you get to the grid.

dataSource: {
  transport: {
    read: "things"
  },
  schema: {
    parse: function (data) {
      // return a new collection which has a new field
      // that adds fields 2 and 3 together
      return $.map(data, function(item) {
       item.field4 = item.field2 + item.field3;
          return item;
      });
    }
  }
}

Here is an example...

http://jsbin.com/azizaz/1/edit

like image 30
Burke Holland Avatar answered Oct 03 '22 23:10

Burke Holland