From Documentation

Jump to: navigation, search







When a user interacts with Spreadsheet like clicking or editing, these actions trigger events being sent to the server. We can implement our business logic in a event listener, a method in a controller, to listen events we are interested in. When the event we listen is triggered, our special business logic is performed. This mechanism helps you customize Spreadsheet furthermore to fulfill your business needs.

ZK Spreadsheet supports numerous events such as mouse events, key events, selection events, editing events and hyperlink events. You can listen to these events to apply customized function upon your business requirement. For example by listening to editing events such as onStartEditing and onStopEditing you can control which cell the user can edit, what is entered/edited and possibly apply some styling or value transformation once the editing is stopped. Similarly, you can also listen to mouse events such as onCellClick or onCellRightClick and update other ZK components or pop up a menu.

In following sections, we will present examples of listening events and they all use SelectorComposer which provides a quite simple way to listen a event, just apply @Listen on a method and specify listening event names and target components. (For complete explanation, please refer to ZK Developer's Reference/MVC/Controller/Wire Event Listeners). In a event listener, you can access book model with Spreadsheet provided API or use your service classes to implement business logic.

A typical sample of defining an event listener is like:

public class EventsComposer extends SelectorComposer<Component>{
	//other codes...

	@Listen("onCellFocus= #ss")
	public void myEventListener(CellEvent event){
		//access book model or perform your business logic
	}
}
  • Line 4: In @Listen, "onCellFocus" is the event name we want to listen (All event name can be found in Events.) and "#ss" is the component selector. (SelectorComposer supports various selector syntax that let you select components easily. Please refer to ZK Developer's Reference/MVC/Controller/Wire Components) .
  • Line 5: The argument passed into a event listener depends on the event it listens. You can get event related data like row or column for further processing.


All ZSS events you can listen are listed in Events



All source code listed in this book is at Github.



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