如何设置大型Handsontable的所有单元格的对齐方式和宽度?

How to set the alignment and width of all cells of a large Handsontable?

如何简单地设置所有单元格的对齐方式和宽度?

谢谢。

迈克尔

编辑:这是我修改过的问题 - 如何设置大型 Handsontable 的所有单元格的对齐方式和宽度?是否可以一次访问所有单元格或遍历单元格?

如果您想为 table 中的每个单元格设置相同的宽度和相同的对齐方式,那么您只需将以下内容添加到您的选项对象中:

{
    "colWidths": 200,      // where 200 is an example width in pixels
    "className": "htRight" // this is an example; you can choose from 
                                  "htRight", "htLeft", "htMiddle", "htBottom", and "htTop"
}

如果使用 type 而不是 text,则 text-align 属性 具有高优先级。因此,要使用 CSS 覆盖它,您可以添加以下规则;这是关于您使用的任何 className 的示例,并假设您希望将其固定在右侧。

.htCenter {
    text-align:right!important;
}

并且在代码中的任何位置,您都可以使用 updateSettings() 更新这些设置。

为了对齐,只需将 className 参数添加到 json 实例

 var hot = new Handsontable(container, {
    className: "htCenter",   //htCenter or htRight
 });