Anyone know how to detect the change in cell data in ng-grid. I want to
call save only if the cell data is changed. Now it calls save whenever
focus is out from the cell but I need to call it only when cell data is
chenged in the grid cell. My code looks like this:
*directive*
angular.module('app', [])
.directive('ngBlur', function () {
return function (scope, elem, attrs) {
elem.bind('blur', function () {
scope.$apply(attrs.ngBlur);
});
};
});
*ng-grid controller*
var cellEditableTemplate = "<input ng-class=\"'colt' + col.index\"
ng-input=\"COL_FIELD\" ng-model=\"COL_FIELD\" ng-blur=\"updateEntity(col,
row, row.getProperty(col.field))\"/>"
//get data
.....
.....
//display data
$scope.gridOptions = {
data: 'agencies',
enablePaging: true,
showFooter: true,
enableCellSelection: true,
pagingOptions: $scope.pagingOptions,
enableCellEditOnFocus: true,
multiSelect: false,
totalServerItems: 'totalItems',
columnDefs: [{ field: 'properties.description', displayName:
'Name', enableCellEdit: true, editableCellTemplate: cellEditableTemplate },
{ field: 'properties.phone1', displayName: 'Phone',
enableCellEdit: true, editableCellTemplate: cellEditableTemplate },
{ field: 'More Info', DisplayName: 'More Info',
enableCellEdit: false, cellTemplate: moreInfoCellTemplate }]
};
$scope.updateEntity = function (col, row, cellVal) {
window.alert("(Agency ID: " + row.entity.id + ") " +
col.displayName + " = " + cellVal + " is saved");
};
Thank you.
On Fri, Dec 27, 2013 at 11:28 AM, Bradford Smith <[email protected]>wrote:
> Here's the full example:
> http://plnkr.co/edit/cQEtn4OLI9xho8lbi9rD?p=preview
>
>
> On Friday, December 27, 2013 11:18:00 AM UTC-5, Bradford Smith wrote:
>>
>> It's been forever since I looked at angular, so bear with me. I'm
>> currently playing with two modules: angular-table an ng-quick-repeat.
>> angular-table currently uses ng-repeat. I'm trying to replace it with
>> ng-quick-repeat to play around. Why can't my demoController see the
>> modifications that angular-table made to the
>> QuickList.value('quickRepeatList')?
>> Doing a console.log in the quickNgRepeat directive shows that the value
>> has changed. The demoController always sees {}, though.
>>
>> QuickTable has the following:
>>
>> angular.module('QuickList', []);
>>
>> angular.module('QuickList').value('quickRepeatList', {});
>>
>> angular.module('QuickList').directive('quickNgRepeat',
>> ['$parse', '$animate', 'quickRepeatList', function($parse, $animate,
>> quick_repeat_list) {
>> ...
>> quick_repeat_list['foo'] = function() { ... }
>> }
>>
>>
>> angular-table now uses quick-ng-repeat:
>>
>> angular.module('angular-table', ['QuickList']).service('ManualCompiler',
>> ['TemplateStaticState', function(TemplateStaticState) {
>> ...
>> rowTemplate = rowTemplate.replace('<tr',
>> '<tr quick-ng-repeat="row in model |
>> orderBy:SortState.sortExpression:SortState.sortDirectionToColumnMap[SortState.sortExpression]
>> | filter:filterQueryModel" quick-repeat-list="items" ' +
>> selectedBackgroundColor + ngClick);
>> ...
>> }
>>
>> The demo:
>>
>> angular.module('demo', ['angular-table', 'QuickList'])
>> .controller('demoController', ['$scope', 'quickRepeatList',
>> function($scope, quickRepeatList) {
>> $scope.selectedRow = {};
>> $scope.listOfNumbers = [];
>>
>> $scope.addRows = function(numberOfRowsToAdd) {
>> var startIndex = $scope.listOfNumbers.length;
>> var endIndex = $scope.listOfNumbers.length +
>> numberOfRowsToAdd;
>>
>> for(var i = startIndex; i < endIndex; i++) {
>> $scope.listOfNumbers.push({
>> id: i,
>> name: 'name ' + i,
>> street: 'street ' + i
>> });
>> }
>> };
>>
>> $scope.handleRowSelection = function(row) {
>> $scope.selectedRow = row;
>> };
>>
>> $scope.addRows(1050);
>> console.log(quickRepeatList);
>> //quickRepeatList.items($scope.listOfNumbers);
>> }]);
>>
>>
>> Here's a plunkr where I try to emulate what's going on, but it may or may
>> not be the same: http://plnkr.co/edit/d5sIDIOboRePAGRwVWSi?p=preview
>>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
Tek Raj Bhatta
Toledo,OH
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.