2017-05-24 2 views
0

나는 아래와 같은 UI를 그리드 컬럼 정의가 :전화 기능이

$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 ""; 
    } 
} 

]

각 cellEditableCondition에 대해 & cellClass에 대해 함수가 호출됩니다. 모든 열 정의에 대해 함수를 정의하고 싶지 않습니다. 대신 한 번 정의하고 모든 열에 대해 호출하고 싶습니다.

누군가가 우리가 함수를 정의하는 데 필요한 범위를 알려주고 어떻게 호출 할 수 있습니까?

감사합니다!

+0

그것은 각도 관련 질문하지만, AngularJS와 일이 아니다. 태그 수정을 허용합니다. – trichetriche

답변

0

당신은 기능을 수행 할 수 있습니다

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