2015-02-05 98 views
3

我需要一次編輯多個單元格。我添加了一個columnDef,每行有一個編輯按鈕。我希望編輯按鈕允許根據條件編輯儘可能多的列。個別行的強制編輯模式ui grid 3.0

當我設置如下的條件時,這隻會檢查當雙擊單元格時是否滿足此條件。

$scope.gridOptions.cellEditableCondition: function(scope){ 
    scope.row.entity.name = "Jay" 
} 

有沒有辦法在符合條件的所有單元格的整行上調用網格的「編輯模式」?

+0

你有沒有得到這個答案?我正在尋找只在編輯模式下添加了所有字段的新行,這樣我就不必另外維護一個表單了。與此類似:http://vitalets.github.io/angular-xeditable/#editable-row – Michael 2015-02-20 01:11:21

+1

我還沒有找到解決此問題的方法。不幸的是,我過去一直在使用可編輯,並習慣於這種API。我現在正在使用ui-grid,並且非常想念這種能力,但即使缺少了一些功能,您也可以通過ui-grid獲得很多。 – kevindstanley 2015-02-20 01:33:43

+0

嗨kevindstanley,你是否能夠找到一種方式來調用除單擊單元格之外的行上的編輯模式? – 2016-06-13 16:09:57

回答

1

我一直在研究一個類似的問題,主要不同之處在於行可以基於數據中的標誌(而不是單獨的按鈕)編輯。你可以see it in action here;這是鏈接斷開時的代碼。

index.html:

<!DOCTYPE html> 
<html ng-app="rowLockDemo"> 
    <head> 
    <meta charset="utf-8" /> 
    <title>Angular UI-Grid row-lock/cell-edit demo</title> 
    <script>document.write('<base href="' + document.location + '" />');</script> 
    <script data-require="[email protected]" src="https://code.angularjs.org/1.2.28/angular.js" data-semver="1.2.28"></script> 
    <script src="http://ui-grid.info/release/ui-grid-unstable.js"></script> 
    <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid-unstable.css" type="text/css"> 
    </head> 
    <body> 
    <div ng-controller="MainCtrl"> 
     <div ui-grid="gridOptions" ui-grid-edit ui-grid-cellNav class="grid"></div> 
     <strong ng-show="msg.lastCellEdited">Last Edit:</strong> {{msg.lastCellEdited}} 
    </div> 
    <script src="app.js"></script> 
    </body> 
</html> 

app.js:

var app = angular.module('rowLockDemo', ['ui.grid', 'ui.grid.edit', 'ui.grid.cellNav']); 

app.controller('MainCtrl', function($scope, $http) { 
    $scope.msg = {}; 

    $scope.gridOptions = { 
    enableCellEdit: false, // set all columns to non-editable unless otherwise specified; cellEditableCondition won't override that 
    enableCellEditOnFocus: true, // set any editable column to allow edit on focus 
    cellEditableCondition: function($scope) { 
     // put your enable-edit code here, using values from $scope.row.entity and/or $scope.col.colDef as you desire 
     return $scope.row.entity.isActive; // in this example, we'll only allow active rows to be edited 
    } 
    }; 

    $scope.gridOptions.columnDefs = [ 
    {name: 'isActive', displayName: 'Edit Status', enableColumnMenu: false, cellTemplate: 'cellTemplate_lock.html'}, // displays isActive status as a button and allow toggling it 
    {name: 'name', enableCellEdit: true}, // editing is enabled for this column, but will be overridden per row by cellEditableCondition 
    {name: 'company', enableCellEdit: true} // same for this column 
    ]; 

    $scope.gridOptions.onRegisterApi = function(gridApi) { 
    $scope.gridApi = gridApi; 
    gridApi.edit.on.afterCellEdit($scope, function(rowEntity, colDef, newValue, oldValue) { 
     $scope.msg.lastCellEdited = 'ID: ' + rowEntity.id + ', Column: ' + colDef.name + ', New Value: ' + newValue + ', Old Value: ' + oldValue; 
     $scope.$apply(); 
    }); 
    }; 

    $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json').success(function(data) { 
    $scope.gridOptions.data = data; 
    }); 
}) 

cellTemplate_lock.html:

<!-- 
    Button shows current state (locked/unlocked); clicking it toggles the state. 

    Initial button state is set by retrieved read-only grid data; lock state is not persisted. 
--> 

<button ng-click="row.entity.isActive = !row.entity.isActive" ng-model="row.entity.isActive" style="{{row.entity.isActive ? 'background-color: lightgreen' : ''}}"> 
    {{ row.entity.isActive ? 'Unlocked' : 'Locked' }} 
</button> 
+0

這只是使用標準的api的cellEditableCondition,但是當一行是'可編輯的'(在您的情況下解鎖)時,仍然不顯示2個輸入框。 UI-Grid 3的api中的CellEdit之後仍然是標準的。也沒有選擇可以觸發,甚至「afterRowEdit」,這將允許一個事件的保存回調到服務器。 – kevindstanley 2015-03-26 14:33:16

4

如果您只想下方的網格的一些列應用條件的例子:

columnDefs: [ 
     // default 
    { field: 'FileName', displayName: 'FileName', enableCellEdit: false, cellTooltip: true }, 
    { field: 'RootFilePath', displayName: 'RelativePath', cellTooltip: true, enableCellEdit: false }, 
    { name: 'File Properties', enableFiltering: false, cellTemplate: '<center><div>' + '<a href="~/../../TaxonomyVersion/GetTaxonomyVersionDetails">View</a>' + '</div></center>' }, 
    { field: 'IsEditable', displayName: 'Editable/NonEditable', headerTooltip: true, enableCellEdit: false }, 
    { field: 'HttpPath', displayName: 'HttpPath', enableCellEdit: true, cellTooltip: true }, 
    { name: 'Generate HttpPath', cellTemplate: '<center><input type="checkbox" ng-model="row.entity.ToGenerateHttpPath", ng-checked="row.entity.ToGenerateHttpPath", ng-click="grid.appScope.generateHttpPath(row.entity.ToGenerateHttpPath,row.entity.HttpPath)"></center>', enableFiltering: false, headerTooltip: true, enableCellEdit: false }, 
    {field: 'TopLevelSchemaComments', displayName: 'Top Level\n Comments', headerTooltip: true, enableFiltering: true, cellTooltip: true, 
     cellEditableCondition: function ($scope) { 
      // put your enable-edit code here, using values from $scope.row.entity and/or $scope.col.colDef as you desire 
      return $scope.row.entity.IsEditable; // in this example, we'll only allow editable rows to be edited 
     }, 
    }, 
    { name: 'Remove', enableFiltering: false, cellTemplate: '<div><center><button ng-disabled ="!(row.entity.IsEditable)" class="fa fa-trash-o" ng-click="grid.appScope.Remove(row.entity.XsdSchemaID,row.entity.XbrlLinkbaseID)"></button></center></div>', enableCellEdit: false }, ] 

如果您希望enitre網格的所有列都遵循相同的條件,那麼只需在columnDefs之前的gridOptions中放置條件即可。下面是例子:

$scope.gridOptions1 = { 
    enableFiltering: true, 
    data: [], 
    showGridFooter: true, 
    enableGridMenu: true, 
    enableColumnResizing: true, 
    cellEditableCondition: function ($scope) { 
     // put your enable-edit code here, using values from $scope.row.entity and/or $scope.col.colDef as you desire 
     return $scope.row.entity.IsEditable; // in this example, we'll only allow editable rows to be edited 
    }, 
    columnResize: true, 
    columnDefs: [ 
     // default 
    { field: 'FileName', displayName: 'FileName', cellTooltip: true }, 
    { field: 'RootFilePath', displayName: 'RelativePath', cellTooltip:true}, 
    { name: 'File Properties', enableFiltering: false, cellTemplate: '<center><div>' + '<a href="~/../../TaxonomyVersion/GetTaxonomyVersionDetails">View</a>' + '</div></center>' }, 
    { field: 'IsEditable', displayName: 'Editable/NonEditable', headerTooltip: true}, 
    { field: 'HttpPath', displayName: 'HttpPath', cellTooltip: true }, 
    { name: 'Generate HttpPath', cellTemplate: '<center><input type="checkbox" ng-model="row.entity.ToGenerateHttpPath", ng-checked="row.entity.ToGenerateHttpPath", ng-click="grid.appScope.generateHttpPath(row.entity.ToGenerateHttpPath,row.entity.HttpPath)"></center>', enableFiltering: false, headerTooltip: true, enableCellEdit: false }, 
    {field: 'TopLevelSchemaComments', displayName: 'Top Level\n Comments', headerTooltip: true, enableFiltering: true, cellTooltip: true}, 
    { name: 'Remove', enableFiltering: false, cellTemplate: '<div><center><button ng-disabled ="!(row.entity.IsEditable)" class="fa fa-trash-o" ng-click="grid.appScope.Remove(row.entity.XsdSchemaID,row.entity.XbrlLinkbaseID)"></button></center></div>', enableCellEdit: false }, ] 
} 
相關問題