Tôi đã gắn bộ não của mình nhưng không thể tìm ra cách phát hiện thay đổi dữ liệu ô trong lưới ng. Đoạn mã sau đang sử dụng ng-thay đổi mà thực hiện đúng cách gọi save(), nhưng nó không phải là kích hoạt Tôi muốn vì nó được gọi cho bất kỳ mục nhập khóa nào. Tôi cần biết khi nào chỉnh sửa ô đã hoàn tất.Phát hiện các thay đổi của tế bào trong angular.js và ng-lưới
Mọi trợ giúp sẽ được đánh giá cao.
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);
}
}]);
nếu bạn có hai (hoặc nhiều hơn) lưới trong cùng một phạm vi, làm thế nào để bạn biết lưới nào trong số này đã kích hoạt sự kiện 'ngGridEventEndCellEdit'? – sports
Sử dụng 'event.targetScope.gridId' bạn có thể xác định lưới nào đã phát ra sự kiện này. –