柱子移动/重新排列

时间:2016-04-05 11:35:40

标签: angularjs angular-ui-grid

我正在使用UI Grid。我有一个plnkr here

var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.pinning', 'ui.grid.moveColumns']);

app.controller('MainCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
  $scope.gridOptions = {};

  $scope.gridOptions.columnDefs = [
    { name:'id', width:50, pinnedLeft:true  },
    { name:'name', width:100, pinnedLeft:true },
    { name:'age', width:100, pinnedLeft:true  },
    { name:'company', width:100},
    { name:'address.street', width:150  },
    { name:'address.city', width:150 },
    { name:'address.state', width:50 },
    { name:'address.zip', width:50 },
    { name:'email', width:100 },
    { name:'phone', width:200 },
    { name:'about', width:300 },
    { name:'friends[0].name', displayName:'1st friend', width:150 },
    { name:'friends[1].name', displayName:'2nd friend', width:150 },
    { name:'friends[2].name', displayName:'3rd friend', width:150 },
  ];
  $scope.gridOptions.jqueryUIDraggable= false;

  $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
    .success(function(data) {
      $scope.gridOptions.data = data;
    });
}]);

,我希望实现以下目标:

  1. 要固定在左侧的前3列
  2. 我希望能够通过拖放它们来移动/重新排列其他非固定列
  3. 我能够实现这两个目标。

    但是,我无法停止/阻止固定列的拖放。 如何防止某些列被拖放?

1 个答案:

答案 0 :(得分:0)

在app.js中,尝试将enableColumnMoving:false添加到columnDefs,如下所示:

var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.pinning', 'ui.grid.moveColumns']);

app.controller('MainCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
  $scope.gridOptions = {};

$scope.gridOptions.columnDefs = [
{ name:'id', width:50, pinnedLeft:true, enableColumnMoving:false },
{ name:'name', width:100, pinnedLeft:true, enableColumnMoving:false },
{ name:'age', width:100, pinnedLeft:true, enableColumnMoving:false  },
{ name:'company', width:100},
{ name:'address.street', width:150  },
{ name:'address.city', width:150 },
{ name:'address.state', width:50 },
{ name:'address.zip', width:50 },
{ name:'email', width:100 },
{ name:'phone', width:200 },
{ name:'about', width:300 },
{ name:'friends[0].name', displayName:'1st friend', width:150 },
{ name:'friends[1].name', displayName:'2nd friend', width:150 },
{ name:'friends[2].name', displayName:'3rd friend', width:150 },
];    

$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
  $scope.gridOptions.data = data;
});
}]);