如何禁用(不删除)gwt celltable 中的列

How to disable(not remove) a column in celltable of gwt

我是 GWT.I 的新手,我知道 tablename.removeColumn(列名) 可用于删除该列,但我不想删除它,而是想禁用它。谁能帮忙 提前致谢!

有一些方法可以做到这一点,但下面是一种简单明了的方法:

public static class CustomTextInputCell extends TextInputCell {
    @Override
    public void render(Context context, String value, SafeHtmlBuilder sb) {
        String url = Window.Location.getHref(); 
        boolean isEditable = url.contains("xyz");

        if (isEditable)  //Condition if editable or not
            super.render(context, value, sb);
        else if (value != null) {
            sb.appendEscaped(value);
        }
    }
}

每次渲染此单元格时都会调用渲染方法。所以每次它都会检查是否满足启用的条件。 这允许您保留可编辑单元格的所有功能,但在满足条件时轻松禁用它。

你这样用

Column<YOUR_OBJECT_HERE, String> column = new Column<YOUR_OBJECT_HERE, String>(new CustomTextInputCell()); 
cellTable.addColumn(column , "YOUR_HEADER_HERE");

我最终创建了一个包含我想要的列的新组件,并根据 url

调用了该组件
String url = Window.Location.getHref(); 
boolean value = url.contains("xyz");
if(value)
{
  component.setEnable(true);
 }
else{
  componentprevious.setEnable(true);
     }

enter code here