gwtsmartgwtgwt2listgrid

setData in ListGrid in SmartGWT


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.


Solution

  • 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