ngHandsontable shows no content on rest service call

眉间皱痕 提交于 2020-01-05 10:32:12

问题


I'm trying in a lot of different ways to get a ngHandsontable to get working with a rest service.

I've allready searched everywhere to get any example... unfortunately all examples are just using static variable definitions and no service calls for the data. Has anybody a working example for that use case?


回答1:


This might be a bit late for you but I have an example that fakes a REST service using a function. You can modify it to put in a real REST call instead. http://plnkr.co/edit/GPYTdJ

function MainCtrl($scope) {
  this.settings = {

  };
  this.data = [
    ["Year", "Kia", "Nissan", "Toyota", "Honda"],
    ["2008", 10, 11, 12, 13],
    ["2009", 20, 11, 14, 13],
    ["2010", 30, 15, 12, 13]
  ];
  var that = this;
  $scope.fakeRestRequest = function () {
    var restData = [
      ["Year", "Kia", "Mazda", "Toyota", "Honda"],
      ["2018", 13, 41, 12, 13],
      ["2019", 23, 41, 14, 13],
      ["2020", 33, 45, 12, 13]
    ];
    that.data = restData;
  };
}

angular
  .module('app', ['ngHandsontable'])
  .controller('MainCtrl', MainCtrl);
  
<!DOCTYPE html>
<html data-ng-app="app">

<head>
  <script src="https://code.angularjs.org/1.4.5/angular.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.19.0/handsontable.full.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ngHandsontable/0.7.0-beta3/ngHandsontable.js"></script>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/handsontable/0.19.0/handsontable.full.css" />

</head>

<body ng-controller="MainCtrl as ctrl">
  <h2>Handsontable Stackoverflow REST Question</h2>

    <div id="grid">
        <hot-table
          col-headers="true"
          row-headers="false"
          datarows="ctrl.data"
          settings="ctrl.settings">
        </hot-table>
    </div>
    
    <button type="button" ng-click="fakeRestRequest()">Update Data</button>
    
</body>

</html>


来源:https://stackoverflow.com/questions/28201244/nghandsontable-shows-no-content-on-rest-service-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!