简体   繁体   English

如何在UI网格中排序列?

[英]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用于第二列。

Here is a Plunker 这是一个柱塞

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM