package sgwtlayouttest.client;

import com.smartgwt.client.types.FetchMode;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;

public class SummaryGrid extends ListGrid {
    
    private static int FIELDS = 12;
    private static int ROWS = 30;

    public SummaryGrid() {
        setSelectionType(SelectionStyle.MULTIPLE);
        setCanEdit(false);
        setCanSelectText(true);
        setCanDragSelectText(false);
        setShowAllRecords(true);
        setBodyOverflow(Overflow.VISIBLE);  
        setOverflow(Overflow.VISIBLE);  
        setDataFetchMode(FetchMode.BASIC);
        setPrintAutoFit(false);
        
        ListGridField[] lgFields = new ListGridField[FIELDS]; 
        for (int i = 0; i < lgFields.length; i++) {
            ListGridField lgField = new ListGridField("field_" + i, 100);
            lgFields[i] = lgField;
        }
        setFields(lgFields);
        
        setData(createListGridRecords());
    }

    public ListGridRecord[] createListGridRecords() {
        ListGridRecord[] result = new ListGridRecord[ROWS];
        for (int row = 0; row < ROWS; row++) {
            ListGridRecord record = new ListGridRecord();
            for (int i = 0; i < FIELDS; i++) {
                record.setAttribute("field_" + i, "val" + row + " " + i);
            }
            result[row] = record;
        }
        return result;
    }
    
}
