2013-08-14 10 views
5

में सेल परिवर्तनों का पता लगाना मैंने अपने दिमाग को रैक किया है लेकिन एनजी-ग्रिड में सेल डेटा परिवर्तन का पता लगाने में असमर्थ हूं। निम्न स्निपेट एनजी-चेंज का उपयोग कर रहा है जो सही ढंग से कॉल() को कॉल करता है, लेकिन यह ट्रिगर नहीं है क्योंकि मैं चाहता हूं कि इसे किसी भी कुंजी प्रविष्टि के लिए बुलाया जाए। मुझे पता होना चाहिए कि का संपादन कब पूरा हो गया है।angular.js और ng-grid

किसी भी मदद की सराहना की जाएगी।

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); 
    } 
}]); 

उत्तर

0

आप ब्लर निर्देश बना सकते हैं और जब इनपुट फोकस खो देता है तो सहेजें फ़ंक्शन को कॉल कर सकता है।

app.directive('ngBlur', ['$parse', function($parse) { 
    return function(scope, element, attr) { 
    var fn = $parse(attr['ngBlur']); 
    element.bind('blur', function(event) { 
     scope.$apply(function() { 
     fn(scope, {$event:event}); 
     }); 
    }); 
    } 
}]); 
4

आप ngGridEventEndCellEdit घटना के लिए सुनने के लिए सक्षम होना चाहिए: https://github.com/angular-ui/ng-grid/wiki/Grid-Events:

$scope.$on('ngGridEventEndCellEdit', function(data) { 
    console.log(data); 
}); 

इस पर बहुत ज्यादा नहीं विस्तार से वर्णन किया गया है।

दुर्भाग्य से मैंने अभी तक काम नहीं किया है कि यह घटना मुझे बताती है कि कौन सी पंक्ति/सेल हमने संपादन समाप्त कर लिया है, ताकि मैं इसे बचा सकूं। लेकिन यह शायद एक शुरुआत है। जब एक कक्ष संपादित किया गया है AngularJS and ng-grid - auto save data to the server after a cell was changed

5

इस चाल करना चाहिए, और आप अपने पूर्ण संपादित पंक्ति, दे:

वैकल्पिक रूप से, stackoverflow पर इस सवाल का एक अच्छा जवाब है कि एक एनजी-कलंक निर्देश शामिल है लगता है । जो तुम तो बचा सकता है/अद्यतन

$scope.$on('ngGridEventEndCellEdit', function(event) { 
    $scope.contact = event.targetScope.row.entity; 
    Contacts.save($scope.contact); 
    // console.log($scope.contact); 
}); 
+0

यदि आप एक ही दायरे में दो (या अधिक) ग्रिड है, तुम कैसे जानते हो जो इन ग्रिड का 'ngGridEventEndCellEdit' गतिविधि सक्रिय? – sports

+0

'event.targetScope.gridId' का उपयोग करके आप यह पहचान सकते हैं कि किस ग्रिड ने इस ईवेंट को उत्सर्जित किया है। –

1

मैं इस किसी की मदद करेंगे उम्मीद है। मुझे भी ngGridEventEndCellEdit ईवेंट में ग्रिड के नाम की आवश्यकता थी।

समारोह के अंदर jQuery का उपयोग कर:

$scope.$on('ngGridEventEndCellEdit', function (data) { 
var gridName = $('.' + data.targetScope.gridId).attr('ng-grid'); 
}); 
4

आप यूआई ग्रिड 3.0 का उपयोग कर रहे या 4.x आपको इंतजार करना चाहिए, तो के लिए: uiGridEventEndCellEdit

$scope.$on('uiGridEventEndCellEdit', function (data) { 
    console.log(data.targetScope.row.entity); 
}); 
0

ui ग्रिड 3.0 के लिए। 6 मैंने afterCellEdit ईवेंट का उपयोग किया था।

$scope.gridOptions.onRegisterApi = function (gridApi) { 
     $scope.gridApi = gridApi; 

     gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef,newValue,oldValue){ 

     if(newValue != oldValue){ 
      // Do something....... 
      // colDef.field has the name of the column that you are editing 
     } 

     }); 

}