angularjs - How to save rows in a grid that I made a change to -


i used ng-resource data server , place data table grid this:

<div ng-form name="grid">       <button type="submit" data-ng-disabled="grid.$pristine">save</button>         <div class="no-margin">             <table width="100%" cellspacing="0" class="form table">                 <thead class="table-header">                     <tr>                         <th>id</th>                         <th>title</th>                     </tr>                 </thead>                 <tbody class="grid">                     <tr data-ng-repeat="row in grid.data">                         <td>{{ row.contentid }}</td>                         <td><input type="text" ng-model="row.title" /></td>                     </tr>                 </tbody>             </table>         </div> </div> 

is there way can make clicking on submit button checks through grid rows changed , calls putentity(row) function row argument?

you few ways, , remember every ngmodelcontroller has $dirty flag can use check if input has changed. easiest way this:

edit html:

<input type="text" ng-model="row.title" ng-change="row.changed=true" /> <button ng-click="save()">save</button> 

in js:

$scope.save = function () {     // iterate through collection , call putentity changed rows     var data = $scope.grid.data;     (var = 0, len = data.length; < len; i++) {         if (data[i].changed) {             putentity(data[i]);         }     } } 

Comments