如何动态更改Handsontable的高度参数

问题描述 投票:0回答:2

我正在使用Handsontable作为我的项目,我需要动态更改高度参数。例如,如果我设置预定义的高度值,那么如果一次行数较少,那么具有该表的div容器将具有更多的剩余空间。我尝试通过在declare表中删除height变量。然后高度自动调整大小,没有剩余空间。但是从宽度侧表也已经超出了div容器。这有什么工作吗?

javascript html handsontable
2个回答
0
投票

创建表时使用高度函数

...    
[height]="getHeight()"
...

然后指定您想要的任何逻辑。 我过去曾使用过这个函数来解决类似的问题:

getHeight() {
  if (!this.targetData)
    return 250; // empty table height

  // this.hotRowHeight is the height of your row
  // rowheight * (number of rows + 3)
  // The extra 3 while calculating height: 2 for header and another for scrollbar
  var calculatedTableHeight = this.hotRowHeight * (this.targetData.length + 3); 
  var maxTableHeight = window.screen.height * 0.7;

  // sets the height of the spreadsheet to 70% of screen height or table height - whichever is smaller
  return Math.min(calculatedTableHeight, maxTableHeight);
}

0
投票
hot.updateSettings({height:'500'})

我使用updateSettings方法动态改变动手高度。

© www.soinside.com 2019 - 2024. All rights reserved.