Zgubiłem swój mózg, ale nie jestem w stanie dowiedzieć się, jak wykryć zmianę danych komórki w ng-grid. W poniższym fragmencie zastosowano zmienną ng, która poprawnie wywołuje metodę save(), ale nie jest to wymagane wywołanie , ponieważ jest wywoływane dla dowolnego wpisu z kluczem. Muszę wiedzieć, kiedy komórka jest kompletna.Wykrywanie zmian w komórkach w angular.js i ng-grid
Każda pomoc zostanie doceniona.
angular.module('controllers', ['ngGrid']).
controller('ContactsListCtrl', ['$scope', 'Contacts', function ($scope, Contacts) {
var editableCellTemplate = '<input type="text" ng-class="\'colt\' + col.index" ng-input="COL_FIELD" ng-model="COL_FIELD" ng-change="save()"/>';
Contacts.get(function(data) {
$scope.contacts = data;
});
$scope.gridOptions = {
data: 'contacts',
enableCellSelection: true,
enableRowSelection: false,
enableCellEdit: true,
showSelectionCheckbox: true,
columnDefs: [
{field: 'lastName', displayName: 'Last Name', enableCellEdit: true, editableCellTemplate: editableCellTemplate},
{field: 'firstName', displayName: 'First Name', enableCellEdit: true, editableCellTemplate: editableCellTemplate},
{field: 'email', displayName: 'EMail Address', enableCellEdit: true, editableCellTemplate: editableCellTemplate},
{field: 'phone', displayName: 'Phone', enableCellEdit: true, editableCellTemplate: editableCellTemplate}
]
};
$scope.save = function() {
$scope.contact = this.row.entity;
Contacts.save($scope.contact);
}
}]);
jeśli masz dwie (lub więcej) sieci w takim samym zakresie, jak wiesz, który z tych siatek oddał 'zdarzenie ngGridEventEndCellEdit'? – sports
Używając "event.targetScope.gridId" można określić, która sieć emitowała to zdarzenie. –