我有一个类似
的JSON{
x:1,
y:2
}
这意味着当我将它贴在我的网格上时,x
列是第一列,y
列是第二列。但是,我想要反过来:y
然后x
。
如何告诉UI网格在y
之前显示x
?
答案 0 :(得分:1)
使用columnDefs
。
在html中定义你的网格,如下所示:
<div id="grid1" ui-grid="gridOptions" class="grid"></div>
您的应用代码如下:
var app = angular.module('app', ['ui.grid']);
app.controller('MainCtrl', ['$scope',
function($scope) {
$scope.myData = [{
"x": "1",
"y": "2",
}, {
"x": "3",
"y": "4",
}];
$scope.gridOptions = {
data: 'myData'
};
$scope.gridOptions.columnDefs = [{
name: 'y'
}, {
name: 'x'
},
];
}
]);
请注意columnDefs
第一列使用y
而第二列使用x
。
这是Plunker