Appearance
支持禁用
可以通过实现 ISupportDisable 支持禁用。实现禁用属性的单元格可以和单元格权限或设置单元格属性命令集成。
C# 示例代码如下
csharp
public class MyPluginCellType : CellType, ISupportDisable
{
[DisplayName("禁用")]
public bool IsDisabled { get; set; }
}JavaScript 通过重写 disable 与 enable 函数实现禁用效果
示例代码如下
javascript
class MyPluginCellType extends Forguncy.Plugin.CellTypeBase {
createContent() {
this.input = $("<input style='width:100%;height:100%'>");
this.input.change(() => {
this.commitValue();
})
return this.input;
}
setValueToElement(_, value) {
this.input.val(value?.toString());
}
getValueFromElement() {
return this.input.val();
}
disable() {
super.disable(); // 这里必须调用基类方法
if (this.isDisabled()) { // 这里必须通过isDisabled方法判断是否真正禁用,否则支持单元格权限时会有问题
this.input.attr("disabled", "disabled")
}
}
enable() {
super.enable(); // 这里必须调用基类方法
if (!this.isDisabled()) { // 这里必须通过isDisabled方法判断是否真正禁用,否则支持单元格权限时会有问题
this.input.removeAttr("disabled");
}
}
}
Forguncy.Plugin.CellTypeHelper.registerCellType("MyPlugin.MyPluginCellType, MyPlugin", MyPluginCellType);重写 disable enable 方法需要注意
- 必须调用 super.disable/enable 方法
- 使用 this.isDisabled() 获取真实的禁用状态
更新: 2022-12-11 20:55:57
原文: https://www.yuque.com/robert-bh51n/ea8l6c/prhvaq61r0qfd1pr