Delete Range"

From Documentation
m
Line 3: Line 3:
 
__TOC__
 
__TOC__
  
ZK Spreadsheet can use Range.delete to delete row or column.
+
===Purpose===
 +
ZK Spreadsheet can use Range.delete <javadoc method="delete(java.lang.Integer)">org.zkoss.zss.model.Range</javadoc> to delete row or column.
  
==Scenario==
+
===ZUML===
User right click to open a menu and delete row or column.
 
 
 
===ZUML Example===
 
 
<source lang="xml" high="4,10">
 
<source lang="xml" high="4,10">
 
<zk>
 
<zk>
Line 28: Line 26:
 
</source>
 
</source>
  
===Open menu===
+
===Composer===
 +
====Open menu====
 
We can use onCellRightClick to get the current mouse position and open popup.
 
We can use onCellRightClick to get the current mouse position and open popup.
 
<source lang="java" high="7,8,9,10">
 
<source lang="java" high="7,8,9,10">
Line 46: Line 45:
 
[[File:ZKSsEss_Spreadsheet_DeleteRange_Menu.png]]
 
[[File:ZKSsEss_Spreadsheet_DeleteRange_Menu.png]]
  
===Shift cells left===
+
====Shift cells left====
 
<source lang="java" high="3">
 
<source lang="java" high="3">
 
public void onClick$shiftCellLeft() {
 
public void onClick$shiftCellLeft() {
Line 56: Line 55:
 
[[File:ZKSsEss_Spreadsheet_DeleteRange_ShiftLeft.png]]
 
[[File:ZKSsEss_Spreadsheet_DeleteRange_ShiftLeft.png]]
  
===Shift cells up===
+
====Shift cells up====
 
<source lang="java" high="3">
 
<source lang="java" high="3">
 
public void onClick$shiftCellUp() {
 
public void onClick$shiftCellUp() {
Line 66: Line 65:
 
[[File:ZKSsEss_Spreadsheet_DeleteRange_ShiftUp.png]]
 
[[File:ZKSsEss_Spreadsheet_DeleteRange_ShiftUp.png]]
  
===Delete entire row===
+
====Delete entire row====
 
<source lang="java" high="5">
 
<source lang="java" high="5">
 
public void onClick$deleteEntireRow() {
 
public void onClick$deleteEntireRow() {
Line 78: Line 77:
 
[[File:ZKSsEss_Spreadsheet_DeleteRange_Row.png]]
 
[[File:ZKSsEss_Spreadsheet_DeleteRange_Row.png]]
  
===Delete entire column===
+
====Delete entire column====
 
<source lang="java" high="4">
 
<source lang="java" high="4">
 
public void onClick$deleteEntireColumn() {
 
public void onClick$deleteEntireColumn() {

Revision as of 01:57, 23 November 2010


Purpose

ZK Spreadsheet can use Range.delete Range.delete(Integer) to delete row or column.

ZUML

<zk>
<div height="100%" width="100%" apply="demo.DeleteRangeComposer">
	<div height="3px"></div>
	<menupopup id="cellMenupopup">
		<menuitem id="shiftCellLeft" label="Shift cells left"></menuitem>
		<menuitem id="shiftCellUp" label="Shift cells up"/>
		<menuitem id="deleteEntireRow" label="Entire row" />
		<menuitem id="deleteEntireColumn" label="Entire column" />
	</menupopup>
	<spreadsheet id="spreadsheet" src="/demo_sample.xls"	
			maxrows="200" 
			maxcolumns="40"
			width="100%"
			height="450px"></spreadsheet>
</div>
</zk>

Composer

Open menu

We can use onCellRightClick to get the current mouse position and open popup.

int rowIndex;
int colIndex;
Sheet currentSheet;
Spreadsheet spreadsheet;
Menupopup cellMenupopup;
public void onCellRightClick$spreadsheet(CellMouseEvent event) {
	rowIndex = event.getRow();
	colIndex = event.getColumn();
	currentSheet = event.getSheet();
	cellMenupopup.open(event.getPageX(), event.getPageY());
}

ZKSsEss Spreadsheet DeleteRange Menu.png

Shift cells left

public void onClick$shiftCellLeft() {
	Range rng = Ranges.range(currentSheet, rowIndex, colIndex);
	rng.delete(Range.SHIFT_LEFT);
}

ZKSsEss Spreadsheet DeleteRange ShiftLeft.png

Shift cells up

public void onClick$shiftCellUp() {
	final Range rng = Ranges.range(currentSheet, rowIndex, colIndex);
	rng.delete(Range.SHIFT_UP);
}

ZKSsEss Spreadsheet DeleteRange ShiftUp.png

Delete entire row

public void onClick$deleteEntireRow() {
	Row row = currentSheet.getRow(rowIndex);
	int lCol = row.getFirstCellNum();
	int rCol  = row.getLastCellNum();
	Ranges.range(currentSheet, rowIndex, lCol, rowIndex, rCol).delete(Range.SHIFT_UP);
}

ZKSsEss Spreadsheet DeleteRange Row.png

Delete entire column

public void onClick$deleteEntireColumn() {
	int tRow = currentSheet.getFirstRowNum();
	int bRow = currentSheet.getPhysicalNumberOfRows();
	Ranges.range(currentSheet, tRow, colIndex, bRow, colIndex).delete(Range.SHIFT_LEFT);
}

ZKSsEss Spreadsheet DeleteRange Column.png

Version History

Last Update : 2010/11/23


Version Date Content
     


All source code listed in this book is at Github.


Last Update : 2010/11/23

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