Checkbox example
Some hints about checkbox template:
The checkbox template can display cell value (true, false or mixed), cell text and cell image at the same time.
Whether the checkbox is checked or clear depends on cell value property (true=checked, false=clear, everything else=mixed). If you want your cell text to correspond the checkbox state - you have to write a function which translate one to another (at some point I am planning to add AW.Formats.Boolean class for this).
Complete example:
The checkbox template can display cell value (true, false or mixed), cell text and cell image at the same time.
obj.setCellTemplate(new AW.Templates.Checkbox, 1);
obj.setCellText("some text", 1);
obj.setCellImage("favorites", 1);
obj.setCellValue(false, 1);
Whether the checkbox is checked or clear depends on cell value property (true=checked, false=clear, everything else=mixed). If you want your cell text to correspond the checkbox state - you have to write a function which translate one to another (at some point I am planning to add AW.Formats.Boolean class for this).
Complete example:
<html>
<head>
<script src="../../runtime/lib/aw.js"></script>
<link href="../../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<input type=button value="See What's Checked" onClick="getChecked();"><br>
<script>
var obj = new AW.UI.Grid;
obj.setControlSize(600, 250);
obj.setCellText(function(i, j){return j + "-" + i});
obj.setHeaderText("header");
obj.setColumnCount(10);
obj.setRowCount(15);
// this is 'normal' checkbox
// it changes cell 'value', not selection
obj.setCellTemplate(new AW.Templates.Checkbox, 2);
// set initial value for column 2
obj.setCellValue(false, 2);
// needed to get "checked" state
obj.setCellText(function(col, row){return this.getCellValue(col, row) ? "yes" : "no"}, 2);
document.write(obj);
obj.onCellValueChanged = function(value, column, row){
window.status = "Cell " + column + "." + row + " changed to " + value;
}
function getChecked() {
for(var i=0;i<obj.getRowCount();i++) {
if(obj.getCellValue(2,i)) {
alert(i);
}
}
}
</script>
</body>
</html>
Alex (ActiveWidgets)
December 5,