我在我的smartgwt項目與listgrid控制。我想要一些動態機制來填充listgrid和動態列(列名和列數不能從開頭定義)。它完全動態來自數據庫。smartgwt動態listgrid動態字段
我該如何在不知道字段名稱和字段號的情況下填充我的listgrid。
我在我的smartgwt項目與listgrid控制。我想要一些動態機制來填充listgrid和動態列(列名和列數不能從開頭定義)。它完全動態來自數據庫。smartgwt動態listgrid動態字段
我該如何在不知道字段名稱和字段號的情況下填充我的listgrid。
我在許多項目中都使用過listgrid。據我所知,我不認爲有一個動態的出路在列表中添加列。但在那些情況下,我用於循環。
只需從數據庫中計數字段並創建for循環。如果您不知道列的名稱,只需使用temp + i作爲名稱來創建它。
最後將所有字段添加到listgrid。即使在添加循環和最大計數值時也是如此。
如果你有一個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.