Data Validation"
m |
m (correct highlight (via JWB)) |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{ZKSpreadsheetEssentialsPageHeader}} | {{ZKSpreadsheetEssentialsPageHeader}} | ||
+ | |||
+ | {{Deprecated|url=http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials}} | ||
+ | |||
+ | |||
+ | |||
__TOC__ | __TOC__ | ||
{{ZSS EE}} | {{ZSS EE}} | ||
===Purpose=== | ===Purpose=== | ||
− | Data validation is invaluable when a workbook | + | Data validation is an invaluable feature when a workbook is shared among other users in an organization to make sure that the data entered in the workbook is accurate and consistent. |
===Data Validation=== | ===Data Validation=== | ||
Line 18: | Line 23: | ||
[[File:ZKSsEss_Spreadsheet_DataValidation_Alert_dialog.png]]<br/> | [[File:ZKSsEss_Spreadsheet_DataValidation_Alert_dialog.png]]<br/> | ||
− | + | Clicking the cancel button will remove the editing value | |
+ | <br /> | ||
<br/> | <br/> | ||
[[File:ZKSsEss_Spreadsheet_DataValidation_Prompt.png]]<br/> | [[File:ZKSsEss_Spreadsheet_DataValidation_Prompt.png]]<br/> | ||
− | + | Clicking the retry button allow users to continue editing the cell value without emptying the editing value | |
<br/> | <br/> | ||
+ | <br /> | ||
[[File:ZKSsEss_Spreadsheet_DataValidation_Alert_Illegal.png]]<br/> | [[File:ZKSsEss_Spreadsheet_DataValidation_Alert_Illegal.png]]<br/> | ||
Line 39: | Line 46: | ||
===Composer=== | ===Composer=== | ||
− | |||
− | <source lang="java" | + | The composer prepares required data from DataValidation (in this case, the four departments - Finance, IE, Sales, R&D) , in order for users to input a value from combobox. |
+ | |||
+ | <source lang="java" highlight="2,7,9,11,22 "> | ||
private DataValidation getDataValidation() { | private DataValidation getDataValidation() { | ||
return sheet.getDataValidation(DATA_VALIDATION_ROW, DATA_VALIDATION_COL); | return sheet.getDataValidation(DATA_VALIDATION_ROW, DATA_VALIDATION_COL); | ||
Line 70: | Line 78: | ||
</source> | </source> | ||
− | Select value | + | Select value<br/> |
[[File:ZKSsEss_Spreadsheet_DataValidation_SelectValue.png]]<br/> | [[File:ZKSsEss_Spreadsheet_DataValidation_SelectValue.png]]<br/> | ||
− | + | Validate and set cell value<br/> | |
[[File:ZKSsEss_Spreadsheet_DataValidation_InputValue.png]]<br/> | [[File:ZKSsEss_Spreadsheet_DataValidation_InputValue.png]]<br/> | ||
− | Select illegal value | + | Select illegal value<br/> |
[[File:ZKSsEss_Spreadsheet_DataValidation_SelectIllegalValue.png]]<br/> | [[File:ZKSsEss_Spreadsheet_DataValidation_SelectIllegalValue.png]]<br/> | ||
− | Error alert | + | Error alert<br/> |
[[File:ZKSsEss_Spreadsheet_DataValidation_InputIllegalValue.png]]<br/> | [[File:ZKSsEss_Spreadsheet_DataValidation_InputIllegalValue.png]]<br/> | ||
+ | |||
+ | View complete source of ZUML [http://code.google.com/p/zkbooks/source/browse/trunk/zssessentials/examples/WebContent/config/validation.zul validation.zul] | ||
+ | |||
+ | View complete source of composer [http://code.google.com/p/zkbooks/source/browse/trunk/zssessentials/examples/src/org/zkoss/zssessentials/config/ValidationComposer.java ValidationComposer.java] | ||
=Version History= | =Version History= |
Latest revision as of 12:55, 19 January 2022
This article is out of date, please refer to http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials for more up to date information.
Available in ZK Spreadsheet EE only
Purpose
Data validation is an invaluable feature when a workbook is shared among other users in an organization to make sure that the data entered in the workbook is accurate and consistent.
Data Validation
Validation message
Prompt
Error alert
Clicking the cancel button will remove the editing value
Clicking the retry button allow users to continue editing the cell value without emptying the editing value
ZUML
<div apply="org.zkoss.zssessentials.config.ValidationComposer" width="100%" vflex="1">
<combobox id="deparmentCombobox">
</combobox>
<spreadsheet id="spreadsheet" src="/WEB-INF/excel/config/validation.xlsx"
maxrows="100" maxcolumns="20"
width="100%" vflex="1">
</spreadsheet>
</div>
Composer
The composer prepares required data from DataValidation (in this case, the four departments - Finance, IE, Sales, R&D) , in order for users to input a value from combobox.
private DataValidation getDataValidation() {
return sheet.getDataValidation(DATA_VALIDATION_ROW, DATA_VALIDATION_COL);
}
private void initCombobox() {
DataValidation dataValidation = getDataValidation();
DataValidationConstraint constraint = dataValidation.getValidationConstraint();
switch (constraint.getValidationType()) {
case ValidationType.LIST:
ListModelList model = new ListModelList(constraint.getExplicitListValues());
deparmentCombobox.setModel(model);
break;
}
//Add illegal item
((ListModelList) deparmentCombobox.getModel()).add("Illegal cell value");
}
public void onSelect$deparmentCombobox() {
String cellValue = deparmentCombobox.getSelectedItem().getLabel();
boolean validInput = spreadsheet.validate(sheet, DATA_VALIDATION_ROW, DATA_VALIDATION_COL, cellValue, null);
if (validInput) {
Ranges.range(sheet, DATA_VALIDATION_ROW, DATA_VALIDATION_COL).setEditText(cellValue);
}
}
View complete source of ZUML validation.zul
View complete source of composer ValidationComposer.java
Version History
Version | Date | Content |
---|---|---|
Since 2.2.0 | January, 2012 | Support Data Validation |
All source code listed in this book is at Github.