2017-11-11 50 views
0

我與角UI電網工作。我正試圖完成一些應該相當簡單的事情,但是找不到任何有效的東西。所有我想要做的就是允許用戶編輯網格,然後必須點擊取消按鈕的選項:嘗試刷新角UI網格上取消編輯單擊

<icon name="cancel" ng-disabled="$ctrl.canceldisabled" ng-click="$ctrl.cancelBSS()" size="20px" title="Cancel"></icon> 

該圖標將會基本上刷新網格,或設置網格單元恢復到上次保存值。會不會只是在這種情況下,電網工作的一個簡單的刷新:

public cancelBSS() { 
     ctrl.gridApi.grid.refresh(); 
    }; 

我試過最API選項 - notifyDataChange,我已經嘗試重置gridOptions.data恢復到上次保存的狀態,但都不要什麼都不做。 沒有什麼變化。

回答

1

你可以嘗試保存屬性oldValue上開始單元格編輯,然後在單擊按鈕恢復:

$scope.gridOptions.onRegisterApi = function(gridApi) { 
    gridApi.edit.on.beginCellEdit(null, function (rowEntity, colDef, newValue, oldValue) {      
     $scope.savedCell = { 
      entityHashKey: rowEntity.$$hashKey, 
      field: colDef.field, 
      value: rowEntity[colDef.field] 
     } 
    }); 
} 

$scope.cancelEdit = function() { 
    var row = $scope.gridApi.grid.rows.find(function(row) { 
     if($scope.savedCell != null) 
      return row.entity.$$hashKey == ctrl.savedValue.entityHashKey; 
    }) 
    if(row == undefined) 
     return; 
    row.entity[$scope.savedCell.field] = $scope.savedCell.value; 
} 
+0

這是偉大的,謝謝。唯一改變的是「colDef.field」實際上是「colDef.name」,並且在if條件中更新爲「ctrl.savedCell.entityHashKey」。欣賞輸入! – bschmitty