Question

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?

Était-ce utile?

La solution

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

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top