UI格保存更新单元数据数据库 [英] ui grid save updated cell data to database

查看:164
本文介绍了UI格保存更新单元数据数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作网格UI编辑细胞的功能。我需要更新编辑的单元格的值使用REST API的数据库。此外,我怎么能得到中行控制器选择列表
我的工作code

I am working on ui grid edit cell feature. I need to update the edited cell value to the database using rest api. Also how can i get the list of rows selected in controller my working code

var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.edit']);

    app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
      $scope.gridOptions = {  };

      $scope.gridOptions.columnDefs = [
        { name: 'id', enableCellEdit: false},
        { name: 'name' },
        { name: 'age', displayName: 'Age' , type: 'number', width: '10%' }
      ];


      $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
        .success(function(data) {
          $scope.gridOptions.data = data;
        });
    }])

http://plnkr.co/edit/kAQnXGTn12Z7v8w16RL9?p=$p $ PVIEW

推荐答案

以下内容添加到您的控制器:

Add the following to your controller:

$scope.gridOptions.onRegisterApi = function(gridApi) {
  //set gridApi on scope
  $scope.gridApi = gridApi;
  gridApi.edit.on.afterCellEdit($scope, function(rowEntity, colDef, newValue, oldValue) {
    //Do your REST call here via $http.get or $http.post

    //Alert to show what info about the edit is available
    alert('Column: ' + colDef.name + ' ID: ' + rowEntity.id + ' Name: ' + rowEntity.name + ' Age: ' + rowEntity.age);
  });
};

您都哪些柱编辑(在 colDef.name )的信息和细胞的实际值是什么(在 rowEntity .XXX )。

You have all the information about which column was edited (in colDef.name) and what the actual values of the cells are (in rowEntity.xxx).

所有你现在要做的就是打电话给你的REST API(以避免不必要的流量,您也可以比较为newValue 属性oldValue ,看看是否真的内容被更改)。

All you have to do now is call your REST API (to avoid unnecessary traffic, you could also compare newValue to oldValue to see if the content really was changed).

您不需要重新加载数据,因为这些更改已经应用到的范围。

You don't need to reload the data, because the changes are already applied to the scope.

查找分叉Plunker这里

你的问题的第二部分:

您行无可选择。而这可能会有点复杂。请开始对这个问题一个新的问题(用新Plunker)。

None of your rows are selectable. And this may get a bit complicated. Please start a new Question (with a new Plunker) about this issue.

这篇关于UI格保存更新单元数据数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆