0

Best way to get a specific cell value from grid

asked 2011-04-05 17:04:30 +0800

bztom33 gravatar image bztom33
104 3

Hello,

How would like retrieve a specific cell value from grid in the composer?

<grid model="@{datas.DATAS}" >
<rows>
<row self="@{each='DATAS'}">
	    			      <label value="@{DATAS.getWa_seq_id}"  />  
	         		      <label value="@{DATAS.getWorkAgreementID}"/>
				       <label value="@{DATAS.getDistrictName}" />
         			       <label value="@{DATAS.getpLast}" />
					<label value="@{DATAS.getpFirst}" />
					<label value="@{DATAS.getpType}" />
					<label value="@{DATAS.getTermDate}" />
					<label value="@{DATAS.getTotalPCost}" />
                                   <!-- Quick test first. -->
		      		<div>
                            <button  id="editButton"  label="Edit" >
	                  	   <attribute name="onClick">
	                          <![CDATA[
	                           // how would I get the value from this cell (@{DATAS.getWa_seq_id}) when clicking on this button.
	                         ]]></attribute> 
                           
	                       </button> 
	              </div>
</row>
<rows>
</grid>

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-04-05 18:58:26 +0800

twiegand gravatar image twiegand
1807 3

updated 2011-04-05 18:59:33 +0800

bztom33,

I'm a fan of using custom attributes. Here is an example that uses the concept:

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<zk>
	<zscript>
		import org.zkoss.zk.ui.util.GenericForwardComposer;
		
		public class Car {
			private String makeModel;

			public Car(String m) {
				setMakeModel(m);
			}

			public String getMakeModel() {
				return makeModel;
			}
			public void setMakeModel(String m) {
				makeModel = m;
			}
		}
			
		List Cars = new ArrayList();
		Cars.add(new Car("Bugatti Veyron"));
		Cars.add(new Car("SSC Ultimate Aero"));
		Cars.add(new Car("Saleen S7 Twin-Turbo"));
		Cars.add(new Car("Koenigsegg CCX"));
		Cars.add(new Car("McLaren F1"));
			
		public class myController extends GenericForwardComposer {
			public Grid myGrid;
			
			public void onClickButton(Event event) {
				Object clickedCar = event.getOrigin().getTarget().getAttribute("theMakeModel");
				alert("You clicked on the " + clickedCar);
			}
	
		}	
	</zscript>

	<window id="main" apply="myController" style="padding: 25px;">
		<grid id="myGrid" fixedLayout="true" model="@{Cars}" hflex="min">
			<columns>
				<column label="Make & Model" width="150px" style="font-weight: bold;"/>
				<column width="100px" align="center"/>
			</columns>
			<rows>
				<row self="@{each=Car}">
					<cell><label value="@{Car.makeModel}" /></cell>
					<cell>
						<button label="Tell Me" forward="onClick=onClickButton()">
							<custom-attributes theMakeModel="@{Car.makeModel}"/>
						</button>
					</cell>
				</row>
			</rows>
		</grid>
	</window>
</zk>

Hope that helps,

Todd

link publish delete flag offensive edit

answered 2011-04-06 14:47:52 +0800

bztom33 gravatar image bztom33
104 3

Many Thanks twiegand!

I finally got it to work. It turns out I did not use the <cell> elements on my original code.

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: 2011-04-05 17:04:30 +0800

Seen: 563 times

Last updated: Apr 06 '11

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