2012-04-30 52 views
1

嗨,我想使用SmartGWT在SmartGWT ListGrid中的setData

我有ArrayList中

ArrayList<FileDocument> documentsArrayList = new ArrayList<FileDocument>(); 

//所有值都在documentsArrayList

和一張桌子

private ListGrid getDocumentTable() { 
     if (documentTable == null) { 
      documentTable = new ListGrid(); 
      documentTable.setSize("644px", "379px"); 
      documentTable.setCanResizeFields(true); 

      documentTable.setFields(getStatus(),getIcon(),getName(),getSize(),getModifiedby(),getModifiedDate()); 
     } 
     return documentTable; 
    } 

電網領域都像

public ListGridField getName() { 
     if (name == null) { 
      name = new ListGridField("name","Name"); 
     } 
     return name; 
    } 

我想說值列表到數組列表值。

documentTable.setData(一些列表網格記錄);

如何轉換ArrayListListGridRecord 這樣我就可以設置數據。

回答

2

您需要創建將Accpet頭你ArrayList作爲輸入的方法和返回使用listGrid.setData(ListGridRecord[] records);

揭開序幕例ListGridRecord數組這反過來又可以設置:

listGrid.setData(getListridRecords(employees)); // set records here 

private void getListGridRecords(ArrayList employees) { 
     ListGridRecords records[]=null; 
     if(employees!=null){ 
     records = new ListGridRecord[employees.size()]; 
     for(int cntr=;cntr<employees.size();cntr++){ 
     ListGridRecord record = new ListGridRecord(); 
     Employee emp = employees.get(cntr); 
     record.setAttribute("name",emp.getName()); //your ListGridField 's name 
     record.setAttribute("status",emp.getStatus()); //your ListGridField 's name 
     //.. more goes here 
     records[cntr] = record; 
     } 

    } 
    return records; 
} 

另一種方式能被this

+0

哎呀我的錯誤。我已編輯它:) –

+0

你能幫我解決這個問題嗎?[link](http://stackoverflow.com/q/10412060/780393) – GameBuilder

+0

有什麼問題嗎? –

0

您還可以使用類

一個數組列表可以CONV直接插入recordList,可以將其添加到ListGridField的setData方法中。 以下是實現的代碼片段。

`RecordList recordList = new RecordList(); 
for(DocumentsArrayList documentsArray: documentsArrayList) 
{ 
    Record record = new Record(); 
    record.setAttribute("Name", getName()); 
    record.setAttribute("size", getSize()); 
    record.setAttribute("user", getuser()); 
    recordList.add(record); 
}   
documentTable.setData(recordList); 
} 

` 所有的屬性名稱應在POJO匹配值,使得值對象,可直接使用。