HandsOnTable:-“错误:无法创建新列。当数据源在对象中时

时间:2019-01-04 05:05:59

标签: angular

无法将数据加载到手动表中。请给我建议如何动态加载数据。

角度代码:

    export class AppComponent {
      title = 'HandsOnTable';        
      constructor(){        
      }
       @ViewChild('wrapper') wrapperElement:ElementRef;

      dataset: any[] = [
        {id: 1, name: 'Ted Right', address: 'Wall Street'},
        {id: 2, name: 'Frank Honest', address: 'Pennsylvania Avenue'},
        {id: 3, name: 'Joan Well', address: 'Broadway'},
        {id: 4, name: 'Gail Polite', address: 'Bourbon Street'},
        {id: 5, name: 'Michael Fair', address: 'Lombard Street'},
        {id: 6, name: 'Mia Fair', address: 'Rodeo Drive'},
        {id: 7, name: 'Cora Fair', address: 'Sunset Boulevard'},
        {id: 8, name: 'Jack Right', address: 'Michigan Avenue'},
      ];

      data = [
        ["", "Tesla", "Volvo", "Toyota", "Honda"],
        ["2017", 10, 11, 12, 13],
        ["2018", 20, 11, 14, 13],
        ["2019", 30, 15, 12, 13]
      ];

      id = 'myGrid';
      private hotRegisterer = new HotTableRegisterer();
      customSettings: Handsontable.GridSettings = {
        colHeaders: true,
        rowHeaders:true,
        data:this.data,
        stretchH: 'all',
        allowInsertRow:true,
        contextMenu:true,
        minRows:100,
        minCols:19,
        autoColumnSize:true,
        columnSorting:true,
        colWidths:100,
        mergeCells:true,
        manualColumnResize:true,
        manualRowResize:true,
        startCols:10,
        startRows:10,
        minSpareCols:10,
        minSpareRows:20
      };

     testButtonClick()
     {        
         //Here it is throwing the error while loading the above dataset        
         const instance =  this.hotRegisterer.getInstance(this.id);
         instance.loadData(this.dataset);     
     }        
    }

app.component.html
--

<!--The content below is only a placeholder and can be replaced.-->
<h4 style="">Excel redaction</h4>
<app-header></app-header>
<div #wrapper>
  <hot-table [settings]="customSettings"  [hotId]="id"></hot-table>
</div>`enter code here`
<button (click)="testButtonClick()"></button>

在这里,加载数据抛出如下错误:

  

错误:无法创建新列。在对象中使用数据源时,只能具有第一个数据行,数据模式或“列”设置中定义的列。如果要添加新列,则必须使用数组数据源。 / p>

0 个答案:

没有答案