Customize Row and Column Titles"
From Documentation
Line 35: | Line 35: | ||
</source> | </source> | ||
− | 2. we can get header title by | + | 2. we can get the header title by |
<source lang="java" high="5,7"> | <source lang="java" high="5,7"> | ||
public void onHeaderDoubleClick$spreadsheet(HeaderMouseEvent event) { | public void onHeaderDoubleClick$spreadsheet(HeaderMouseEvent event) { |
Revision as of 09:02, 30 August 2011
Purpose
ZK Spreadsheet can set customized title by Spreadsheet.setColumntitles(Map) or Spreadsheet.setRowtitles(Map)
ZUML
<zk>
<div height="100%" width="100%" apply="demo.HeaderTitleComposer">
<popup id="inputTitlePopup">
<textbox id="titleEditor"/>
</popup>
<div height="3px"></div>
<spreadsheet id="spreadsheet" src="/Untitled"
maxrows="200"
maxcolumns="40"
width="100%"
height="450px"></spreadsheet>
</div>
</zk>
Composer
Current Title
We can use onHeaderClick, onHeaderRightClick or onHeaderDoubleClick to get the current header that user clicked. Here, we use onHeaderDoubleClick as an example.
1. we can get clicked header type by
HeaderMouseEvent.getType();
2. we can get the header title by
public void onHeaderDoubleClick$spreadsheet(HeaderMouseEvent event) {
String currentTitle = null;
int headerType = event.getType();
if (headerType == HeaderEvent.TOP_HEADER) {
currentTitle = spreadsheet.getColumntitle(currentIndex);
} else {
currentTitle = spreadsheet.getRowtitle(currentIndex);
}
...
3. Then, set the current header title to textbox and open the popup.
Popup inputTitlePopup;
Textbox titleEditor;
public void onHeaderDoubleClick$spreadsheet(HeaderMouseEvent event) {
...
inputTitlePopup.open(event.getPageX(), event.getPageY());
titleEditor.setText(currentTitle);
titleEditor.focus();
}
Edit Title
We can change column title when use click Enter
public void onOK$titleEditor() {
HashMap<Integer, String> titles = new HashMap<Integer, String>();
titles.put(Integer.valueOf(currentIndex), titleEditor.getText());
if (isColumnHeader) {
spreadsheet.setColumntitles(titles);
} else {
spreadsheet.setRowtitles(titles);
}
inputTitlePopup.close();
}
Cancel Editing
Close popup when user click Esc
public void onCancel$titleEditor() {
inputTitlePopup.close();
}
View complete source of ZUML headerTitle.zul
View complete source of composer HeaderTitleComposer.java
Version History
Version | Date | Content |
---|---|---|
All source code listed in this book is at Github.