【发布时间】:2018-09-10 11:05:29
【问题描述】:
我在我的项目中使用Handsontable,我需要动态更改高度参数。例如,如果我设置了预定义的高度值,那么如果我的 div 容器中的表一次有更少的行数将有更多剩余空间。我尝试删除声明表中的高度变量。然后高度自动调整大小并且没有剩余空间。但是从宽度侧表也已经超出了 div 容器。有什么解决办法吗?
【问题讨论】:
标签: javascript html handsontable
我在我的项目中使用Handsontable,我需要动态更改高度参数。例如,如果我设置了预定义的高度值,那么如果我的 div 容器中的表一次有更少的行数将有更多剩余空间。我尝试删除声明表中的高度变量。然后高度自动调整大小并且没有剩余空间。但是从宽度侧表也已经超出了 div 容器。有什么解决办法吗?
【问题讨论】:
标签: javascript html handsontable
hot.updateSettings({height:'500'})
我使用 updateSettings 方法来动态改变handsontable高度。
【讨论】:
创建表格时使用高度函数
...
[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);
}
【讨论】: