如何居中对齐 handsontable 中的复选框?

How to center align a checkbox in handsontable?

我正在使用 handsontable,我的代码是用 typescript/aurelia 编写的。我无法居中对齐复选框列。我按照 this link 并将复选框列中的 class 名称设置为 "htCenter htMiddle"。在文本列上这个东西有效但在复选框列上无效。而当我使用我的开发工具并将 <td> 上的 class 设置为 "htCenter htMiddle" 时,它起作用了。是否有任何其他方法可以为此复选框列设置对齐方式?

这是添加class名称的代码:

this.options.columns = [ { data: "modalValue", renderer: linkButtonRenderer, readOnly: true }, { data: "uri", readOnly: true }, { data: "isPublic", className: "htCenter htMiddle", type: "checkbox" } ];

我已经为 Handsontable 0.19.0 解决了这个问题

[handsontable.full.js: line 17197]
function checkboxRenderer(instance, TD, row, col, prop, value, cellProperties)

添加这个以允许使用自定义渲染器(不知道为什么他们错过了这个)

getRenderer('base').apply(this, arguments);

如果您只想对对齐进行硬编码,请将其作为该函数的第一行:

TD.style.textAlign = "center";

你必须设置

{ data: 'Is_anything', type: 'checkbox', className: "htCenter htMiddle" },

像这样。您将在中心看到复选框。

无法设置复选框(和数字)对齐是以前版本的 Handsontable 中的一个错误。自 Handsontable version 0.25.1 --- see https://github.com/handsontable/handsontable/issues/2925 and https://github.com/handsontable/handsontable/issues/3532.

起已修复此问题

OP 的代码现在应该可以工作了。