// starting NEW row index
var serial = 100;
function add(){
obj.addRow(serial++);
}
obj.onRowAdded = function(row){
window.status = "Row added: " + row;
this.setCellText("*New Record*",0, row);
for (k = 1; k <= 14; k++){this.setCellText("-",k, row);}
obj.setCellText(function(col, row){return new Date()}, 1, row);
}
Note: the loop is hard coded to 14 but needs fixing to num of cols!!!
<html> <head>
<script src="../../runtime/lib/aw.js"></script>
<link href="../../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 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)
obj.setCellTemplate(new AW.Templates.Checkbox, 2);
obj.setCellValue(function(col, row){return CellData[row][2]=="t" ? true : false}, 2);
obj.setCellText(function(col, row){return this.getCellValue(col, row) ? "Yes" : "No!"}, 2);
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);
function add(){
obj.addRow(CellData.length++);
}
// I add this according to your response.. Please check if I understand correct.
obj.onRowAdded = function(row){
this.setCellTemplate(new AW.Templates.Checkbox, 2,row);
this.setCellValue(false, 2,row);
this.setCellText(function(col, row){return this.getCellValue(col, row) ? "Yes" : "No!"}, 2,row);
}
</script>
<BR>
<INPUT type="button" id="addbutton" value="add" onclick="add()">
</body> </html>
<html>
<head>
<script src="runtime/lib/aw.js"></script>
<link href="runtime/styles/xp/aw.css" rel="stylesheet"></link>
<script>
var columnHead = [
"Acct No.", "Subcode", "Dpt Atr", "Form type"
];
var CellData = [
["aa","USPS","f","reconciled"],
["bb","Email","t","unreconciled"],
["cc","FedEX","t","reconciled"],
["cc","FedEX","f","hopeless"],
["dd","Phone","f","unreconciled"],
];
</script>
</head>
<body>
<script>
var obj = new AW.UI.Grid;
obj.setCellText(function(c, r){return CellData[r][c]});
obj.setHeaderText(function(c){return columnHead[c]});
obj.setColumnCount(4);
obj.setRowCount(5);
obj.setSize(425, 150);
// add a checkbox to col
obj.setCellTemplate(new AW.Templates.Checkbox, 2);
obj.setCellValue(false, 2);
// to get "checked" state put a function in cell text, which follows the checks!
obj.setCellText(function(col, row){return this.getCellValue(col, row) ? "yes" : "no"}, 2);
document.write(obj);
document.write("<br>");
//START ADD DELETE ROW
obj.onRowAdded = function(row){
window.status = "Row added: " + row;
this.setCellText("*New Record*",0, row);
for (k = 1; k <= 14; k++){this.setCellText("-",k, row);}
obj.setCellText(function(col, row){return new Date()}, 1, row);
}
// row index
var serial = 100;
function add(){
obj.addRow(serial++);
}
</script>
<br><button onclick="add()">add row</button>
</body>
</html>
for (k = 1; k <= 14; k++){this.setCellText("-",k, row);}
obj.setCellText(CellData);
obj.setCellTemplate(new AW.Templates.Checkbox, 2);
obj.setCellValue(function(col, row){return CellData[row][2]=="0" ? true : false}, 2);
obj.setCellTemplate(new AW.Templates.Checkbox, 4);
obj.setCellValue(function(col, row){return CellData[row][4]=="0" ? true : false}, 4);
var celldatalength= CellData.length;
for (k = 0; k <= celldatalength-1; k++){obj.setCellText(CellData[k][4]=="0"? "Yes" : "No",4,k);};
for (k = 0; k <= celldatalength-1; k++){obj.setCellText(CellData[k][2]=="0"? "Yes" : "No",2,k);};
obj.onCellValueChanged = function(value, col, row){
window.status=value;
obj.setCellText(value ? "Yes" : "No",col,row);
}
for (k = 0; k <= celldatalength-1; k++){obj.setCellValue(CellData[k][4]=="0"? true : false,4,k);};
for (k = 0; k <= celldatalength-1; k++){obj.setCellValue(CellData[k][2]=="0"? true : false ,2,k);};
for (k = 0; k <= celldatalength-1; k++){obj.setCellText(CellData[k][4]=="0"? "Yes" : "No",4,k);};
for (k = 0; k <= celldatalength-1; k++){obj.setCellText(CellData[k][2]=="0"? "Yes" : "No",2,k);};
This topic is archived.