Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid Programmically Created Summary Column

    I have been able to create summary columns using the header menu on a ListGrid, but I need to be able to do that automatically in my program. I can't really work with the provided method

    Code:
    refintField.setSummaryFunction(new SummaryFunction() {
      public Object getSummaryValue(Record[] records, ListGridField field) {
        return null;
      }
    });
    since I need to get attributes per record for the refint field, not for all records. I cannot see any other way to do it using the summary code.

    To further illustrate what I've been trying to do, below is a test case. I have lowerBound and upperBound in the data source and I need to have them separate so I can do other calculations on them. But for the purposes of this particular grid, we need to put them in one column with a dash between the values. In the example, this field is represented as "refintField".

    Test.java:
    Code:
    package test;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.RestDataSource;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.util.KeyCallback;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.grid.CellFormatter;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.grid.SummaryFunction;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class Test implements EntryPoint {
    
    	private VLayout layout;
    
    	@Override
    	public void onModuleLoad() {
    	    KeyIdentifier debugKey = new KeyIdentifier();
    	    debugKey.setCtrlKey(true);
    	    debugKey.setKeyName("D");
    
    	    Page.registerKey(debugKey, new KeyCallback() {
    	        public void execute(String keyName) {
    	            SC.showConsole();
    	        }
    	    });
    		layout = new VLayout();
    		
    		ListGrid grid = new ListGrid();
    		grid.setHeight("800");
    		grid.setWidth("600");
    		grid.setAutoFetchData(true);
    		grid.setAlwaysShowEditors(true);
    		
    		RestDataSource gridDS = getDataSource();
    		grid.setDataSource(gridDS);
    		
    		ListGridField nameField = new ListGridField("name");
    		nameField.setCanEdit(false);
    		
    		ListGridField refintField = new ListGridField("refint");
    		refintField.setSummaryFunction(new SummaryFunction() {
    			public Object getSummaryValue(Record[] records, ListGridField field) {
    				return null;
    			}
    		});
    		refintField.setCanEdit(false);
    		refintField.setCellFormatter(new CellFormatter() {
    			public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
    				String lowerBound = record.getAttribute("lowerBound");
    				String upperBound = record.getAttribute("upperBound");
    				return lowerBound + " - " + upperBound;
    			}
    		});
    		
    		grid.setFields(nameField, refintField);
    		
    		layout.addMember(grid);
    		layout.draw();
    	}
    	
    	private RestDataSource getDataSource() {
    		DataSourceField id = new DataSourceTextField("_id", "Id");
    		id.setPrimaryKey(true);
    		id.setRequired(true);
    		id.setHidden(true);
    		
    		DataSourceField name = new DataSourceTextField("name", "Name");
    		name.setRequired(true);
    		
    		DataSourceField lowerBound = new DataSourceTextField("lowerBound", "Lower Bound");
    		lowerBound.setRequired(true);
    		lowerBound.setHidden(true);
    		
    		DataSourceField upperBound = new DataSourceTextField("upperBound", "Upper Bound");
    		upperBound.setRequired(true);
    		upperBound.setHidden(true);
    		
    		RestDataSource datasource = new RestDataSource();
    		datasource.setDataURL("data/test1.xml");
    		datasource.setXmlRecordXPath("//labtest");
    		datasource.setFields(id, name, lowerBound, upperBound);
    		datasource.setClientOnly(true);
    		
    		return datasource;
    	}
    
    }
    test1.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <data>
    	<phase _n="5">
    	    <labtests>
    	        <labtest _id="1">
    	            <name>Test 1</name>
    	            <lowerBound>5.5</lowerBound>
    	            <upperBound>8.5</upperBound>
    	        </labtest>
    	        <labtest _id="2">
    	            <name>Test 2</name>
    	            <lowerBound>12</lowerBound>
    	            <upperBound>18</upperBound>
    	        </labtest>
    	        <labtest _id="3">
    	            <name>Test 3</name>
    	            <lowerBound>37</lowerBound>
    	            <upperBound>55</upperBound>
    	        </labtest>
    	        <labtest _id="4">
    	            <name>Test 4</name>
    	            <lowerBound>60</lowerBound>
    	            <upperBound>77</upperBound>
    	        </labtest>
    	        <labtest _id="5">
    	            <name>Test 5</name>
    	            <lowerBound>19.5</lowerBound>
    	            <upperBound>24.5</upperBound>
    	        </labtest>
    	    </labtests>
    	</phase>
    </data>
    I had been just creating the dummy refintField and combining the values from the record in the cell formatter. This technique was working last Friday (2/5/10) on that day's 2.0 snapshot, but when I came back to it on the following Monday's snapshot, that column was blank and I got errors in the dev console.

    The error I get is:
    Code:
    13:19:43.181:TMR0:WARN:gridEdit:isc_OID_1:startEditing() passed bad cell coordinates:,, can't edit
    13:19:43.220:RDQ3:WARN:Log:TypeError: this.$286 is undefined
    It seems to be linked with the inclusion of grid.setShowAllEditors(true) for if I take it out everything displays just fine. I'm using SmartGWT 2.0-SNAPSHOT (latest) on SC 7.1 and Java 1.6.0_18.

    So, is there a way to use the summary editors for what I need to do? If not, is there a way to display what I need to while keeping all editors open?

    Thanks!
Working...
X