0

How to dynamically update Grid row level total column with RowRenderer?

asked 2012-04-28 05:47:17 +0800

davout gravatar image davout
1435 3 18

I have a complex grid where due to the variable nature of its structure (i.e. variable number of columns) I'm having to use a RowRenderer to build its component content.

The row renderer creates a set of columns that include cell level in place number or combobox components. The very first column of the grid is a Label showing a calculated row level total.

I'm wondering how I can have this row level total Label can be updated as soon as a row level combo box or number component value changes?

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2012-04-29 18:26:52 +0800

davout gravatar image davout
1435 3 18

I have a complex grid that can have a variable number of columns. To handle this I'm using a composer class to build the model, and a RowRenderer class to build the components that go into each column. I've managed to setup binding via the RowRenderer class so that I can call 'getBinder().saveAll()' from the composer class to retrieve changes back into the model.

The grid includes a 'simple score' column that represents a row level summation of values. I'm trying to set up bindings for this simple score column so that any change in the other columns will force a reload of the data into the simple score column.

public void render(Row aRow, EvaluationEditRowDO aDO, int index) throws Exception {
	// find bean identifier
	final String aBeanID = aRow.getUuid();
	// bind bean with incoming data object
	getBinder().bindBean(aBeanID,aDO);
	// create project title label
	RowRendererUtil.addCell(aRow,aDO.getTitle());
	// create decision combo box 
	Combobox aDecision = RowRendererUtil.addInplaceCombox(aDO.getDecisions().getModel(),aDO.getDecisions().getValue());
	// bind decision combo box
	getBinder().addBinding(aDecision,"value",aBeanID+".decisionsValue");
	RowRendererUtil.addCell(aRow, aDecision);
	// create weighted score label
	RowRendererUtil.addCell(aRow,NumberFormat.getInstance().format(aDO.getWeightedScore()));
	// create simple score label
	Label aSimple = RowRendererUtil.addLabel(NumberFormat.getInstance().format(aDO.getSimpleScore()));
	RowRendererUtil.addCell(aRow, aSimple);
	int i=0;
	// use string array to hold name of criteria column components
	ArrayList<String> aLoadEvents = new ArrayList<String>(aDO.getCells().size());
	// add variable number of criteria columns
	for (CellDO aCellDO : aDO.getCells()) {
		// if its a number criteria then create a double box
		if (aCellDO.isNumberCell()) {
			NumberCellDO aNumberCellDO = (NumberCellDO) aCellDO;
			Doublebox aNumber = RowRendererUtil.addInplaceNumber(aNumberCellDO);
			// give the double box a unique ID
			aNumber.setId("numberR" + index+"C"+i);
			// save the row number into a double box attribute
			CellTypeConverter.setCellIndex(aNumber, i);
			// bind the double box into a special method of the bean that can read the row number to set the appropriate array element
			getBinder().addBinding(aNumber,"value",aBeanID+".cellNumber",(List)null,(List)null,null,"com.eis.zk.dataobject.CellTypeConverter");
			RowRendererUtil.addCell(aRow, aNumber);
			// add the double box name and event to the list of components where a change should drive a load for the simple score
			aLoadEvents.add(aNumber.getId()+".onChange");
		}
		else {
			// if its a lookup criteria then create a combo box
			if (aCellDO.isLookupCell()) {
				ComboboxCellDO aComboxboxCellDO = (ComboboxCellDO) aCellDO;
				Combobox aLookup = RowRendererUtil.addInplaceCombox(aComboxboxCellDO.getModel(),aComboxboxCellDO.getValue());
				CellTypeConverter.setCellIndex(aLookup, i);
				aLookup.setId("lookupR"+index+"C"+i);
				getBinder().addBinding(aLookup,"value",aBeanID+".cellString",(List)null,(List)null,null,"com.eis.zk.dataobject.CellTypeConverter");
				RowRendererUtil.addCell(aRow, aLookup);
				// add the combo box name/event to the list of change events to be bound to the simple label
					aLoadEvents.add(aLookup.getId()+".onChange");
			}
		}
		i++;
	}
	// bind the simple score label to a list of criteria column component onChange events
	getBinder().addBinding(aSimple,"value",aBeanID+".simpleScoreStr",null,null,null,null,null,aLoadEvents,null);
}



This leaves me with one problem - how to update a row level total column that should ideally be updated as one of the other custom column values is updated.

In the code above the 'aSimple' label is given a binding that links it to the 'xxx.onChange' events of the variable columns on the same row. This isn't working - any ideas?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-04-28 05:47:17 +0800

Seen: 267 times

Last updated: Apr 29 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More