Basic Knowledge Demo #3 Checkboxes and Two Combo lists (set and get values)
Here at Jim's good suggestion, is the Basic Knowledge demo #3, re-redone so it shows the main point ON the PAGE as well as in comments. Sorry it makes them a bit more complex inside.
Please be sure to edit for your OWN site:
<link href="ActiveWidgets/runtime/styles/classic/aw.css" ...
<script src="ActiveWidgets/runtime/lib/aw.js"....
These demos are designed to be edited and toyed with, to help you learn the basics. Cut and Past the entire code, set the links to aw.js and aw.css properly. Then please post great new ideas or uses for AW.
Here goes,
Basic Knowledge Demo #3:
Checkboxes, setting initial value, and returning values; and Combo template, two different list show, set/get value...
Please be sure to edit for your OWN site:
<link href="ActiveWidgets/runtime/styles/classic/aw.css" ...
<script src="ActiveWidgets/runtime/lib/aw.js"....
These demos are designed to be edited and toyed with, to help you learn the basics. Cut and Past the entire code, set the links to aw.js and aw.css properly. Then please post great new ideas or uses for AW.
Here goes,
Basic Knowledge Demo #3:
Checkboxes, setting initial value, and returning values; and Combo template, two different list show, set/get value...
<html> <head>
<script src="ActiveWidgets/runtime/lib/aw.js"></script>
<link href="ActiveWidgets/runtime/styles/xp/aw.css" rel="stylesheet"></link>
<style>
.aw-column-1 {text-align: right;}
.aw-grid-row {border-bottom: 1px solid threedlightshadow;}
</style>
</head> <body>
<script>
var HeaderText = ["Last Changed col","Best way?","Auto send","Dispose"];
var CellData = [
["aa","USPS","f","reconciled"],
["bb","Email","t","unreconciled"],
["cc","FedEX","t","reconciled"],
["cc","FedEX","f","hopeless"],
["dd","Phone","f","unreconciled"]
];
var popUpSelections_1 = ["Email","Phone","FedEX","USPS"];
var popUpSelections_2 = ["reconciled","unreconciled","hopeless"];
var obj = new AW.UI.Grid;
obj.setHeaderText(HeaderText);
obj.setCellText(function(c,r){return CellData[r][c]} );
//obj.setCellText(CellData); // this makes col setting impossible isBUG ? bug : feature!!!
obj.setSize(450, 120);
obj.setColumnCount(4);
obj.setRowCount(5);
obj.setColumnWidth(120, 0); // set the width wide first col (c0)
// add a checkbox to col 2 (the 3rd col)
obj.setCellTemplate(new AW.Templates.Checkbox, 2);
// set initial VALUE for column 2 From the CellData array NOTE: MUST BE SET to Boolean true/false.
obj.setCellValue(function(col, row){return CellData[row][2]=="t" ? true : false}, 2);
// to get "checked" state put a function in cell text, which follows the checks and writes it back into the CELL!
obj.setCellText(function(col, row){return this.getCellValue(col, row) ? "Yes" : "No!"}, 2);
// Put the Combo "template" (as opposed to the "control") in to second col (c1) & forth (c3)
obj.setCellTemplate(new AW.Templates.Combo, 1);
obj.setCellTemplate(new AW.Templates.Combo, 3);
// Populate the list, set the onClicked to move selection to cell, then hide the list.
obj.setPopupTemplate(function(col, row){
var list = new AW.UI.List;
if(col==1){ // if populating col==1 use this set of selections and this count
list.setItemText(popUpSelections_1); // selection list
list.setItemCount(4); // count
} else{ // all other cols of PopupTemplate use this set of selections
list.setItemText(popUpSelections_2); // different selection list
list.setItemCount(3); // differnt count
}
list.onItemClicked = function(event, i){
var selectedText = this.getItemText(i);
obj.setCellText(selectedText, col, row);
obj.setCellValue(selectedText, col, row);
obj.getCellTemplate(col, row).hidePopup();
}
return list;
});
obj.onCellValueChanged = function(value, col, row){
this.setCellText("c"+col+" r"+row+ " v="+value, 0, row); // show last new value in first col (c0)
if(col == 1)alert("value:"+value+" Column:"+col+" Row:"+row); // alert for second col (c1) only
}
document.write(obj);
</script>
</body> </html>
G Cayman
February 11,