2017-05-24 5 views
0

J'ai une définition de colonne de grille ui comme ci-dessous:fonction d'appel de la définition Grille

$scope.gridOptions.columnDefs = [ 
{ name: 'Year 3', field: 'Year 3', cellEditableCondition: function($scope) { return $scope.row.entity[$scope.col['field']+'_editable']; }, 
    editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownValueLabel: 'yoy', editDropdownOptionsArray: $scope.yoyGrowthDropDown, 
    cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { 
     if (row.entity[col['field']+'_editable']) 
     return 'red'; 
     else 
     return ""; 
    } 
}, 
{ name: 'Year 4', field: 'Year 4', cellEditableCondition: function($scope) { return $scope.row.entity[$scope.col['field']+'_editable']; }, editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownValueLabel: 'yoy', editDropdownOptionsArray: $scope.yoyGrowthDropDown, 
    cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { 
     if (row.entity[col['field']+'_editable']) 
     return 'red'; 
     else 
     return ""; 
    } 
}, 
{ name: 'Year 5', field: 'Year 5', cellEditableCondition: function($scope) { return $scope.row.entity[$scope.col['field']+'_editable']; }, editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownValueLabel: 'yoy', editDropdownOptionsArray: $scope.yoyGrowthDropDown, 
    cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { 
     if (row.entity[col['field']+'_editable']) 
     return 'red'; 
     else 
     return ""; 
    } 
}, 
{ name: 'Year 6-10', field: 'Year 6-10', cellEditableCondition: function($scope) { return $scope.row.entity[$scope.col['field']+'_editable']; }, editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownValueLabel: 'cagr', editDropdownOptionsArray: $scope.cagrDropDown, 
    cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { 
     if (row.entity[col['field']+'_editable']) 
     return 'red'; 
     else 
     return ""; 
    } 
} 

];

Pour chaque celluleEditableCondition & cellClass, une fonction est appelée. Je ne veux pas définir de fonction pour chaque définition de colonne. Au lieu de cela, je veux le définir une fois et l'appeler pour chaque colonne.

Quelqu'un peut-il s'il vous plaît laissez-moi savoir sur quelle étendue avons-nous pour définir la fonction et comment l'appelons-nous?

Merci!

+0

Ce n'est pas une question relative angulaire, mais un AngularJS. Permettez-moi de modifier vos tags – trichetriche

Répondre

0

Vous pouvez le faire avec une fonction:

function isCellEditable(scope) { 
    return scope.row.entity[scope.col['field']+'_editable']; 
} 

function getCellClass(grid, row, col) { 
    return row.entity[col['field']+'_editable'] ? 'red' : ''; 
} 

$scope.gridOptions.columnDefs = [ 
    { name: 'Year 3', field: 'Year 3', cellEditableCondition: isCellEditable, 
    editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownValueLabel: 'yoy', editDropdownOptionsArray: $scope.yoyGrowthDropDown, 
    cellClass: getCellClass 
    }, 
    { name: 'Year 4', field: 'Year 4', cellEditableCondition: isCellEditable, editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownValueLabel: 'yoy', editDropdownOptionsArray: $scope.yoyGrowthDropDown, 
    cellClass: getCellClass 
    }, 
    { name: 'Year 5', field: 'Year 5', cellEditableCondition: isCellEditable, editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownValueLabel: 'yoy', editDropdownOptionsArray: $scope.yoyGrowthDropDown, 
    cellClass: getCellClass 
    }, 
    { name: 'Year 6-10', field: 'Year 6-10', cellEditableCondition: isCellEditable, editableCellTemplate: 'ui-grid/dropdownEditor', editDropdownValueLabel: 'cagr', editDropdownOptionsArray: $scope.cagrDropDown, 
    cellClass: getCellClass 
    } 
    ];