Sunday 15 February 2015

AngularJS and ng-grid - auto save data to the server after a cell was changed -


My use case is very simple A user, after editing a cell (enableCellEdit: true), the data is " "On the server (on cell blur) I tried different methods but none of them is working properly. I have a minimum grid:

  // ng-grid $ scope.gridOptions = {data: 'question', enable cell selection: correct, selected items: $ scope.selectedRow, multiSelect: False, columnDefs: [field: 'id', display name: 'id'}, {field: 'name', display_name: 'name'}, {field: 'answer [1] .valuePercent', displayName: 'rural' Enabled: edit: true}]};   

For example, I tried to see the data model sent to the grid. But by doing this I will not return the edited cell:

  $ scope $ Watch ('myData', function (foo) {// myModel. Update ()} is true);   

I tried to bellow with the "ngGridEventData" data event but editing the cell

  $ scope $ ('NgGridEventData' function (E, GridID) {// myModel. Update ()}); Finally, I tried a cell for the supervisor. However, it works only for one line by the mean of the grid's "selectedCell" property:  
  $ scope.selectedRow = []; $ Scope.gridOptions = {selectedItems: $ scope.selectedRow,} $ scope $ Watch ('selectedRow', function (foo) {console.log (foo)}, true);   

Is it necessary? I can not believe that this is nothing from the box.

Do you have an indicator / snippet that I can save myself / send to the server? Perhaps this is new, but the NG-Grid actually publishes events that make a simple change on the basis.

Event reference:

Example code (add to the controller where you set up the grid):

 < Code> $ scope. Find the underlying data / changes that force $ On ('ngGridEventEndCellEdit', function (evt) {console.log (evt.targetScope.row.entity); // line, and send the unit to the server});   

One thing to note is that even if no changes have been made, the event will trigger, so you can check the changes even before sending the server (eg. 'NgGridEventStartCellEdit')

No comments:

Post a Comment