Announcement

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

    How to refer to another summary field in RecordSummaryFunction

    I have a ListGrid with a series of Integer fields followed by two fields of ListGridFieldType.SUMMARY. The first of the two summary fields (perStore) is a simple SUM of the series of Integer fields using the built-in RecordSummaryFunctionType.SUM and works fine.

    The second summary field "extendedTotal" needs to be calculated by multiplying the "perStore" total by another IntegerItem "numberOfStores" on a form in the same Canvas as the ListGrid. I've tried coding the following but am getting a null pointer error on the record.getAttributeAsInt("perStore") line. How can I access the auto-calculated summary field "perStore" and be sure that it has already been calculated by the time the "extendedTotal" summary function executes.
    Code:
    extendedTotal.setRecordSummaryFunction(new RecordSummaryFunction() {
    
    	@Override
    	public Object getSummaryValue(Record record,
    			ListGridField[] fields, ListGridField summaryField) {
    		// Multiply row perStore total by number of stores
    		Object numberOfStoresInt = form.getItem("numberOfStores").getValue();
    		if (numberOfStoresInt==null)
    			return null;
    		return record.getAttributeAsInt("perStore") * (Integer)numberOfStoresInt;
    	}
    	
    });

    #2
    Hi Jay,
    Agreed there should be a straightforward way to do this. We're looking at the best way to add support for it.

    In the meantime you can call the SmartClient method 'getCellValue()' using JSNI - something like this:
    Code:
    	private native String getCellValue (JavaScriptObject grid, JavaScriptObject record, String fieldName) /*-{
    		var rowNum = grid.data.findIndex(record),
    			colNum = grid.getFieldNum(fieldName);
    		var result = grid.getCellValue(grid.data.get(rowNum), rowNum, colNum);
    		return result == null ? null : "";		
    	}-*/;
    Your calling code would look like this:
    Code:
    String cellVal = getCellValue(someGrid.getJsObj(), record.getJsObj(), "FieldName");

    Comment


      #3
      Did this ever make it into the API? I'm using the 11-28-2010 nightly and thought I should check before trying the JSNI mentioned earlier.

      Comment


        #4
        You still need to use JSNI for now.

        Comment

        Working...
        X