0

我面临动态创建的剑道 UI 网格的问题。title当我使用和属性指定列数组field并渲染网格时,网格列不显示指定的,title而是显示field名称。我不希望字段名称按原样显示,因为字段名称本身作为列标题没有意义。

注意:这是在角度控制器内完成的。

这是我的网格定义

<div kendo-grid="ctrl.commonGrid" options="ctrl.commonGridOptions"></div>

这是我用来生成列的代码。

var columns = [];

angular.forEach(ctrl.ColumnConfig, function (col) { var newCol ={ title: col.displayName, field: col.mappingProperty.toCamelCase(), } columns.push(newCol); });

在此之后,我将其分配给网格列集合

ctrl.commonGridOptions = { columns: columns, };

然后只需使用网格数据源数据方法来填充数据。

ctrl.commonGrid.dataSource.data(ctrl.TableData);

从昨天开始,我一直在挠头,但无法弄清楚出了什么问题。

谁能帮我吗。

谢谢

4

1 回答 1

0

Ok I fixed this. Following is the code that works as expected. The firstRow is nothing but the row from the list of objects that I fetch from the server, and the columnConfig is the configuration of the columns I want to display.

for (var property in firstRow) { if (firstRow.hasOwnProperty(property)) { model.fields[property] = { type: 'string' }; var col = $.grep(ctrl.columnConfig, function (e) { return e.mappingProperty === property }); if (col.length) { columns.push({ title: col[0].displayName, field: col[0].mappingProperty }); } } }

于 2015-08-19T06:53:41.313 回答