2013-01-17 42 views
5

我想附加兩列綁定到一個劍道網格列。 下面似乎沒有工作。網格如何在一個多個列

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

      }).data("kendoGrid"); 

回答

18

如果您不需要編輯,你可以做所謂由細胞組成或組成細胞,它是實現使用KendoUI template。 (嘗試谷歌搜索「組合單元的肯德威網格」)。

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 #" 
     } 
    ] 
}); 
+0

感謝這工作。 – desiguy

+0

thanx很多老兄! –

6

你看看DataSource上的schema.parse方法嗎?您可以將列添加爲沒有問題的新字段。然後當你到達電網時,該字段將可用。

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; 
     }); 
    } 
    } 
} 

下面是一個例子...

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

3

這裏是一個不同的解決方案,還提供了在任場獨立地進行排序,同時仍保留數據的單個柱的能力。

columns: [ 
    { // cell data 
     headerAttributes: { style: "display:none;" }, 
     attributes: { colspan: 2 }, 
     template: "#= field1 # #= field2 #" 
    }, 
    { // field 1 data 
     field: "field1", 
     title: "Field 1", 
     attributes: { style: "display: none;" }, 
     template: "" 
    }, 
    { // field 2 data 
     field: "field2", 
     title: "Field 2", 
     attributes: { style: "display: none;" }, 
     template: "" 
    } 
] 
+2

而不是'attributes:{style:「display:none;」 }'最好只使用'hidden:true' –

相關問題