我不确定我是否完全理解了这个问题。
您是否正在寻找一种方法来隐藏列上下文菜单中的“国家代码”选项?你可以通过声明来做到这一点
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);
这应该可以解决问题。