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 different approaches but none of them have properly worked out. I have a minimalistic grid:
// Configure ng-grid
$scope.gridOptions = {
data: 'questions',
enableCellSelection: true,
selectedItems: $scope.selectedRow,
multiSelect: false,
columnDefs: [
{field: 'id', displayName: 'Id'},
{field: 'name', displayName: 'Name'},
{field: 'answers[1].valuePercent', displayName: 'Rural', enableCellEdit: true}
]
};
For example, I tried to watch the data model passed to the Grid. But doing so won't return me the edited cell:
$scope.$watch('myData', function (foo) {
// myModel.$update()
}, true);
I tried to fiddle with the "ngGridEventData" data event but it does not fire after cell edit
$scope.$on('ngGridEventData', function (e, gridId) {
// myModel.$update()
});
Finally, I tried to observer a Cell. However, this only work for a row by the mean of the "selectedCell" property of the grid:
$scope.selectedRow = [];
$scope.gridOptions = {
selectedItems: $scope.selectedRow,
}
$scope.$watch('selectedRow', function (foo) {
console.log(foo)
}, true);
Is it a ng-grid plugin needed? I can't believe it is not something out of the box.
Would you have a pointer / snippet how I could solve the auto save / send to the server?
question from:
https://stackoverflow.com/questions/15647981/angularjs-and-ng-grid-auto-save-data-to-the-server-after-a-cell-was-changed 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…