0

我在我的 smartgwt 项目中使用 listgrid 控件。我想要一些动态机制来用动态列填充listgrid(列名和列数不能从​​一开始就定义)。它完全是动态的,来自 db。

在不知道字段名称和字段数量的情况下,我应该如何填写我的列表网格。

4

2 回答 2

0

I have worked with listgrid in many projects. As per my knowledge I don't think there is a dynamic wayout to add columns in listgrid. But in those condition I have used for loop.

Just take count of fields from database and create for loop. if you do not know the name of column just create it with temp + i as name.

And finally add all fields to listgrid. Even at the time of adding use for loop and max count value.

于 2014-10-07T08:54:53.653 回答
0

如果您有一个 ListGrid 并且想要动态添加一列,则必须重新创建所有其他列并添加新列,然后添加 listGrid.setFields。像这样:

List<ListGridField> oldColumns; //here you store the old columns
List<ListGridField> newColumns = new ArrayList<ListGridField>(); //here you store the newColumns
for(ListGridField oldField : oldColumns){
    ListGridField newField = new ListGridField(oldField.getName(), oldField.getTitle());
    newColumns.add(newField);
}
ListGridField field = new ListGridField(newName, newTittle); //Declare the new one
newColumns .add(field);
oldColumns = newColumns;
listGrid.setFields(newColumns); //and your listGrid is updated.
于 2016-04-07T07:46:21.260 回答