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

前端 未结 7 1632
悲哀的现实
悲哀的现实 2020-12-02 08:51

My Use Case is pretty simple. A User, after editing a Cell (enableCellEdit: true), should have the data \"automatically\" sent to the server (on cell blur). I tried differen

相关标签:
7条回答
  • 2020-12-02 09:37

    I've found what I think is a much nicer solution:

      cellEditableTemplate = "<input ng-class=\"'colt' + col.index\" ng-input=\"COL_FIELD\" ng-model=\"COL_FIELD\" ng-change=\"updateEntity(row.entity)\"/>"
    

    Using ng-change this way will cause updateEntity to be called with the entire object (row) that has been changed and you can post it back to the server. You don't need any new scope variables. A deficiency of the previous solution was that when you clicked in to start editing the field, it would always be blank instead of the original value before you began to edit.

    That will cause updateEntity() to be called on each keystroke. If that is too frequent for you, you could use a timeout before posting to the server, or just use updateEntity() to record the id you want to push, and then use ng-blur to post the recorded id.

    0 讨论(0)
提交回复
热议问题