更改 SmartGWT 中的网格列过滤器

发布于 2024-12-11 07:29:41 字数 1051 浏览 0 评论 0原文

如果您在 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 中实现这一点?

If you create a custom DataSource in SmartGWT, is it possible to remove a field filter instead of hiding it entirely from the grid columns?

As seen here:

enter image description here

The Country code field exists, but is hidden in the above image.

Clarification: I want to hide the Country code field at the start, but still have it visible in the Columns context menu. If you use setHidden(true) the field disappears from the Columns menu above.

Example code:

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...
    }

}

How would this be achieved in a ListGrid with the above DataSource?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖公主 2024-12-18 07:29:41

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

您是否正在寻找一种方法来隐藏列上下文菜单中的“国家/地区代码”选项?你可以通过声明来做到这一点
< code>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

DataSource

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

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);

这应该可以解决问题。

I'm not sure if I fully understood the question.

Are you looking for a way to hide the "Country code" option from the Columns context menu? You can do that by declaring
ListGridField.setCanHide(false) to the corresponding ListGridField.

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

Or, are you trying to disable filtering?

If so, does the user have to have the option to see the country code column in some cases?
If not, you can just leave the MyDataSource as it is and define only those ListGridFields that you want the user to see.

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);

The underlying country code attribute is still available in the code, eg. via record.getAttribute("countryCode");, it's just not shown in the ListGrid.

Alternatively, you can define the filtering on grid level with ListGridField.canFilter(Boolean canFilter).

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

EDIT:

So, don't set the hidden attribute in the datasource, but instead directly to the ListGridField.

DataSource

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

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);

That should do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文