AngularJS and ng-grid - auto save data to the server after a cell was changed

前端 未结 7 1660
悲哀的现实
悲哀的现实 2020-12-02 08:51

My Use Case is pretty simple. A User, after editing a Cell (enableCellEdit: true), should have the data \"automatically\" sent to the server (on cell blur). I tried differen

7条回答
  •  悲哀的现实
    2020-12-02 09:13

    Maybe this is new but ng-grid actually publishes events which can be used to implement a simple update on change.

    Event Reference: https://github.com/angular-ui/ng-grid/wiki/Grid-Events

    Example code (add to controller where you setup the grid):

    $scope.$on('ngGridEventEndCellEdit', function(evt){
        console.log(evt.targetScope.row.entity);  // the underlying data bound to the row
        // Detect changes and send entity to server 
    });
    

    One thing to note is that the event will trigger even if no changes have been made, so you may still want to check for changes before sending to the server (for example via 'ngGridEventStartCellEdit')

提交回复
热议问题