【问题标题】:Change grid column filter in SmartGWT在 SmartGWT 中更改网格列过滤器
【发布时间】:2011-10-26 01:12:26
【问题描述】:

如果您在 SmartGWT 中创建自定义 DataSource,是否可以删除字段过滤器而不是将其完全隐藏在网格列中?

如下所示:

国家/地区代码字段存在,但在上图中隐藏

澄清:我想在开始时隐藏国家/地区代码字段,但在上下文菜单中仍然可以看到它。如果您使用setHidden(true),该字段将从上面的菜单中消失。

示例代码:

public class MyDataSource extends DataSource {

    public MyDataSource() {
        DataSourceField countryField = new DataSourceIntegerField("country", "Country code");
        // TODO Find a method that disables the filter, aka hides but not removes the field from the grid.
        countryField.setHidden(true); // Completely hides/removes the field, not desireable.
        countryField.setCanFilter(true); // Doesn't seem to change anything. 
        addField(countryField);

        // Other fields...
    }

}

如何在具有上述数据源的 ListGrid 中实现这一点?

【问题讨论】:

    标签: gwt smartgwt


    【解决方案1】:

    我不确定我是否完全理解了这个问题。

    您是否正在寻找一种方法来隐藏上下文菜单中的“国家代码”选项?你可以通过声明来做到这一点 ListGridField.setCanHide(false) 对应的 ListGridField。

    ListGridField countryCode = new ListGridField("countryCode");
    countryCode.setHidden(true);
    countryCode.setCanHide(false); // won't be shown in the context menu
    

    或者,您是否尝试禁用过滤

    如果是这样,在某些情况下,用户是否必须拥有查看国家代码列的选项? 如果没有,您可以保留 MyDataSource 原样,只定义您希望用户看到的 ListGridFields

    ListGrid grid = new ListGrid();
    ListGridField country = new ListGridField("country");
    ListGridField capital = new ListGridField("capital");
    ListGridField continent = new ListGridField("continent");
    // no countryCode here
    grid.setFields(country, capital, continent);
    

    底层国家代码属性在代码中仍然可用,例如。通过record.getAttribute("countryCode");,它只是没有显示在 ListGrid 中。

    或者,您可以使用ListGridField.canFilter(Boolean canFilter) 定义网格级别的过滤。

    ListGridField countryCode = new ListGridField("countryCode ");
    countryCode.setCanFilter(false);
    

    编辑:

    所以,不要在数据源中设置隐藏属性,而是直接设置ListGridField

    数据源

    public class MyDataSource extends DataSource {
    
      public MyDataSource() {
        DataSourceField countryCode = new DataSourceStringField("countryCode", "Country code");
        DataSourceField country = new DataSourceStringField("country", "Country");
        DataSourceField capital = new DataSourceStringField("capital", "Capital");
        DataSourceField continent = new DataSourceStringField("continent", "Continent");
    
        setFields(countryCode, country, capital, continent);
      }
    }
    

    列表网格

    ListGrid grid = new ListGrid();
    ListGridField countryCode = new ListGridField("countryCode");
    countryCode.setHidden(true);
    countryCode.setCanHide(true); // I don't think this is even necessary.
    ListGridField country = new ListGridField("country");
    ListGridField capital = new ListGridField("capital");
    ListGridField continent = new ListGridField("continent");
    grid.setFields(countryCode, country, capital, continent);
    

    这应该可以解决问题。

    【讨论】:

    • 没有这些情况;我想在开始时隐藏“国家代码”字段,但仍然可以在“列”上下文菜单中看到它。如果您使用 setHidden 或 setCanHide,则不会发生这种情况。例如。这样“国家代码”从一开始就被隐藏,但仍然可以通过“列”菜单打开。希望这有点道理。
    • 太棒了,谢谢!我没有假设 DataSource 字段!= ListGrid 字段,但现在它是如此明显。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 2023-03-17
    • 2020-06-12
    相关资源
    最近更新 更多