Listen to Cell Changes and Action"

From Documentation
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{ZKSpreadsheetEssentialsPageHeader}}
 
{{ZKSpreadsheetEssentialsPageHeader}}
 +
 +
 +
{{Deprecated|url=http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials}}
 +
  
 
__TOC__
 
__TOC__
Line 5: Line 9:
 
Users can write cell change event listeners for those cases when cells' values or styles are changed.
 
Users can write cell change event listeners for those cases when cells' values or styles are changed.
 
===Purpose===
 
===Purpose===
Implement cell change event listeners for any cell contents changes.
+
Implement cell change event listeners for cell contents changes.
  
 
===Cell Change Event===
 
===Cell Change Event===
 
There are one cell change event.
 
There are one cell change event.
* '''onCellChange''' - This event is fired whenever a cell's value or style has changed. Event listeners are provided with <code>org.zkoss.zss.ui.event.CellEvent</code> in the event listener.
+
'''onCellChange''' - This event is fired when user change the contents or styles of a selection directly or indirectly. Event listeners are provided with <javadoc directory="zss">org.zkoss.zss.ui.event.CellSelectionEvent</javadoc> in the event listener.
  
==Registering Cell Events==
+
===Registering Cell Events===
Cell change event can be registered to ZK Spreadsheet either by calling <javadoc method="addEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener)">org.zkoss.zk.ui.AbstractComponent</javadoc> or by using ZK MVC way i.e. using naming convention of <event-name>$<component-id>. Here is an example shown using first way
+
Cell change event can be registered to ZK Spreadsheet either by calling <javadoc directory="zss" method="addEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener)">org.zkoss.zk.ui.AbstractComponent</javadoc> or by using ZK MVC way i.e. using naming convention of <event-name>$<component-id>. Here is an example shown using first way
  
 
<source lang="java">
 
<source lang="java">
Line 19: Line 23:
 
new EventListener() {
 
new EventListener() {
 
public void onEvent(Event event) throws Exception {
 
public void onEvent(Event event) throws Exception {
doCellChangeEvent((CellEvent) event);
+
doCellChangeEvent((CellSelectionEvent) event);
 
}
 
}
 
});
 
});
Line 29: Line 33:
 
<source lang="java">
 
<source lang="java">
 
...
 
...
public void onCellChange$ss(CellEvent event) {
+
public void onCellChange$ss(CellSelectionEvent event) {
doCellChangeEvent(Ranges.range(event.getSheet(), event.getRow(), event.getColumn()));
+
doCellChangeEvent(event);
 
}
 
}
 
...
 
...

Latest revision as of 06:44, 22 August 2013


Listen to Cell Changes and Action




Stop.png This article is out of date, please refer to http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials for more up to date information.


Users can write cell change event listeners for those cases when cells' values or styles are changed.

Purpose

Implement cell change event listeners for cell contents changes.

Cell Change Event

There are one cell change event. onCellChange - This event is fired when user change the contents or styles of a selection directly or indirectly. Event listeners are provided with CellSelectionEvent in the event listener.

Registering Cell Events

Cell change event can be registered to ZK Spreadsheet either by calling AbstractComponent.addEventListener(String, EventListener) or by using ZK MVC way i.e. using naming convention of <event-name>$<component-id>. Here is an example shown using first way

...
ss.addEventListener(org.zkoss.zss.ui.event.Events.ON_CELL_CHANGE,
	new EventListener() {
		public void onEvent(Event event) throws Exception {
			doCellChangeEvent((CellSelectionEvent) event);
		}
	});
...

Note: All ZK Spreadsheet supported events have a corresponding static constants declared in org.zkoss.zss.ui.event.Events class. For example for onCellChange event there is org.zkoss.zss.ui.event.Events.ON_CELL_CHANGE.

Here is an example shown using second way

...
public void onCellChange$ss(CellSelectionEvent event) {
	doCellChangeEvent(event);
}
...

Version History

Last Update : 2013/08/22


Version Date Content
     


All source code listed in this book is at Github.


Last Update : 2013/08/22

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.