2012-04-30 118 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匹配值,使得值对象,可直接使用。