0

ui-grid我想自定义一个用于导入 csv 文件的按钮,而不是那个 ui-grid 中的下拉菜单。我不想更改 ui-grid 中的任何内容,我只想添加一个额外的按钮。这样它就可以在 UI 网格的顶部很容易地看到。

代码

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

app.controller('ViewController', ['$scope', '$http', 'uiGridConstants', function ($scope, $http, uiGridConstants) {

  $scope.gridOptions = {
    enableGridMenu: true,
importerDataAddCallback: function ( grid, newObjects ) {
    //   $scope.data = $scope.data.concat( newObjects );
    $scope.data = newObjects;
    console.log($scope.data);    
    $http.post('/save', $scope.data).then(function(data){
    console.log(data);
      $http.get('/save')
  .success(function(data) {
      $scope.gridOptions.data = data;
    });
    });
  },
    onRegisterApi: function(gridApi) {
            $scope.gridApi = gridApi;
    }
  }

$scope.gridOptions.columnDefs = [
    {name:'name'},
    {name:'age'},
    {name: 'marks'}
  ];   
  $http.get('/save')
  .success(function(data) {
      $scope.gridOptions.data = data;
    });
}])


<div ng-controller="ViewController">

  <div ui-grid="gridOptions" ui-grid-importer ui-grid-selection ui-grid-exporter  class="grid">
    </input>

  </div>
</div>
4

0 回答 0