Reputation: 1189
Hi i am trying to use SmartGWT
.
I have Arraylist
ArrayList<FileDocument> documentsArrayList = new ArrayList<FileDocument>();
// all the value are in the documentsArrayList
and a table
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;
}
fields of the grid are like
public ListGridField getName() {
if (name == null) {
name = new ListGridField("name","Name");
}
return name;
}
I want to put values to array list value to table.
documentTable.setData(some list grid record);
How to convert ArrayList
in ListGridRecord
so that i can set the data.
Upvotes: 2
Views: 8027
Reputation: 425
You can also use the class
A Array list can be converted into a recordList that can be added to the setData method of the ListGridField. Below is the code snippet of the implemention.
`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);
}
` All the attribute name should match the values in the POJO so that the value object can be directly used.
Upvotes: 0
Reputation: 14887
You need to create a method which will accpet your ArrayList
as an input and return an array of ListGridRecord which in turn can be set using listGrid.setData(ListGridRecord[] records);
Kick off Example:
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;
}
Another way could be this
Upvotes: 3