简体   繁体   English

尝试在“取消编辑”单击时刷新Angular Ui-Grid

[英]Trying to refresh Angular Ui-Grid on Cancel Edit click

I am working with the Angular ui-grid . 我正在使用Angular ui-grid I am trying to accomplish something which should be fairly simple but can't find anything that works. 我正在尝试完成一些应该很简单但找不到有效的事情。 All I want to do is allow a user to edit the grid and then have the option to click a cancel button: 我要做的就是允许用户编辑网格,然后可以选择单击取消按钮:

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

This icon will then basically refresh the grid, or set the grid cell back to its last saved value. 然后,该图标将基本上刷新网格,或将网格单元设置回其最后保存的值。 Wouldn't just a simple refresh of the grid work in this case: 在这种情况下,不仅可以简单地刷新网格工作:

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

I've tried most api options - notifyDataChange, I've tried resetting the gridOptions.data back to its last saved state but both don't do anything. 我尝试了大多数api选项-notifyDataChange,尝试将gridOptions.data重置为上次保存的状态,但是两者都不执行任何操作。 Nothing changes. 没有什么变化。

You can try to save oldValue on begin cell edit and then restore it on button click: 您可以尝试在开始单元格编辑时保存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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM