2016-04-05 13 views
0

Ich verwende UI Grid. Ich habe einen plnkr hereSpalte verhindern/verschieben

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; 
    }); 
}]); 

, wo ich folgendes erreichen will:

  1. die ersten 3 Spalten nach links
  2. ich in der Lage sein wollen, gepinnt werden zu verschieben/neu ordnen die andere nicht angeheftete Spalten durch Drag-Drop sie

Ich konnte beides erreichen.

Ich war jedoch nicht in der Lage zu stoppen/verhindern Drag-Drop der Spalten, die fixiert sind. Wie kann ich verhindern, dass bestimmte Spalten per Drag-Drop verschoben werden?

Antwort

0

In dem app.js, versuchen Sie, enableColumnMoving: false zu dem columnDefs etwa so:

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; 
}); 
}]); 
+0

Hier die Plunker ist [link] (http://plnkr.co/edit/C4awJEATlm3JrqZ03Gwf?p=preview) – dovelce

+0

Cool! Genau das habe ich gesucht. :) –

Verwandte Themen