문제

What I'm trying to do is take the "showSelectionCheckbox:" setting in my gridOptions and change it from false to true and get my ng-grid to either show or hide the ng-grid default check box.

My code successfully changes the value, however the changes are not reflected on the grid.

$scope.saveTest() is bound to a button with ng-click.

$scope.gridOption = {
  data: 'myData', 
  showSelectionCheckbox: false, 
  ....
} 

$scope.saveTest = function () {
  $scope.gridOption.showSelectionCheckbox = true;
}

So my question is, is it even possible to change configuration settings on the fly with ng-grid? Is there an event that can be listened for to refresh the grid?

도움이 되었습니까?

해결책

There is no way changing the showSelectionCheckbox property dynamically, but there is always the ugly workaround of using 2 grids and showing one of them based on the selection.

Example:

html:

<button ng-click="changeGrid()">test</button>     
<div class="gridStyle" ng-if="!showSelectionCheckbox" ng-grid="gridOptions"></div>
<div class="gridStyle" ng-if="showSelectionCheckbox" ng-grid="gridOptions2"></div>

js:

var app = angular.module('myApp', ['ngGrid']);

app.controller('MyCtrl', function($scope, $http) {
  $scope.showSelectionCheckbox=false;
    $scope.myData = [{"name": "Moroni", "allowance": 50},
              {"name": "Tiancum", "allowance": 53},
              {"name": "Jacob", "allowance": 27},
              {"name": "Nephi", "allowance": 29}],

    $scope.gridOptions = { 
        data: 'myData',
        showSelectionCheckbox: false, 
        };
       $scope.gridOptions2 = { 
        data: 'myData',
        showSelectionCheckbox: true, 
        };  

 $scope.changeGrid = function () {
  $scope.showSelectionCheckbox=!$scope.showSelectionCheckbox;
 }
});

Live example: http://plnkr.co/edit/4u7iz7R8EKXdoNnoR5MS?p=preview

다른 팁

The 2 grids (hide one and show the other one) workaround is a good solution when you're handling small amounts of data, but if you need to manage thousands of records the process of changing from one grid to another turns very slow. Hope the (ng-grid) component's developers find a good solution to this problem in a near future.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top