Prox4
Prox4

Reputation: 111

How to change ui-grid with gridOption-enableRowselection dynamically in Angular JS

I need to enable and disable rowSelection for view depending on some condition. Problem here is,multiple views use the same html and controller. I need the rowSelection to be disabled for a certain view and enabled in other cases.

I have tried these. 1)Assigned a function for enableRowselection which would return boolean.(Didn't work) 2)Tried with isRowSelectable too.(Didn't work)

Code is as below.Not sure if it is implemented in right way. I'm a beginner in AngularJS and ui-grid 1)

$scope.gridOptions = {
enableRowSelection: isSelectionEnabled
}
 isSelectionEnabled():boolean {
             var seletionEnabled = true;
             if (doesn't satisfy condition) {
                seletionEnabled = false;
             }
            return seletionEnabled ;
         }

2)

$scope.gridOptions = {
isRowSelectable: function() {
                 if(satisfies condition) return true; 
                return false; 
               },
}

Upvotes: 0

Views: 963

Answers (2)

Remko
Remko

Reputation: 359

I assume you know if you want to enable rowselection on creation of the ui-grid. Try something like:

$scope.gridOptions.onRegisterApi = function(gridApi) {
  $scope.gridApi = gridApi;

  $scope.gridOptions.enableRowSelection = $scope.isSelectionEnabled();
};

$scope.isSelectionEnabled = function() {
  // some logic here to determine whether to enable rowselection or not
  return true; // or false
};

You can pretty much change $scope.gridOptions.enableRowSelection anywhere, once the ui-grid has been created.

See this plunker for an example and/or to try out if this is what you want.

Upvotes: 1

Wasef Anabtawi
Wasef Anabtawi

Reputation: 1021

the right property is "enableRowSelection", try the following:

$scope.gridOptions = {
    enableRowSelection: function () { 

     if(condition){
            return true
      } 
      return false; 
    }
}

Upvotes: 0

Related Questions