[英]How can I order the columns in UI-grid?
I have a JSON that is coming in as something like 我有一个像这样的JSON
{
x:1,
y:2
}
Which means when I stick it on my ui-grid, the x
column is first and the y
column is second. 这意味着当我将其粘贴在ui网格上时,
x
列位于第一位, y
列位于第二位。 However, I want the reverse: y
then x
. 但是,我想反过来:
y
然后x
。
How can I tell UI-grid to display y
ahead of x
? 我怎么能告诉UI格显示
y
领先的x
?
By using columnDefs
. 通过使用
columnDefs
。
Define your grid in html like this: 像这样在html中定义网格:
<div id="grid1" ui-grid="gridOptions" class="grid"></div>
And your app code like this: 而您的应用程序代码如下:
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'
},
];
}
]);
Note how columnDefs
uses y
for the first column and x
for the second one. 请注意
columnDefs
如何将y
用于第一列,将x
用于第二列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.