<html>
<head>
<script src="activewidgets/runtime/lib/aw.js"></script>
<link href="activewidgets/runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<script>
var adjustment = 15;
var myColumns = [
["a","this is some long text", "a very very very long line of text", "another long piece of text"],
["a","this is some long text", "1234", "another long <BR>piece of text<BR>that is multi-line"],
["a","this is some long text", "1234", "another long piece of text"],
["a","this is some long text", "1234", "another long piece of text"],
["a","this is some long text", "1234", "another long piece of text"],
["a","this is some long text", "1234", "another long piece of text"],
["a","this is some long text", "1234", "another long piece of text"],
["a","this is some long text", "1234", "another long piece of text"]
];
var obj = new AW.UI.Grid;
obj.setCellText(myColumns);
obj.setHeaderText(["header 1", "header 2", "header 3", "header 4"]);
obj.setColumnCount(4);
obj.setRowCount(8);
obj.setRowHeight(40);
obj.getRowTemplate().setClass("text", "wrap");
obj.setCellTemplate(new AW.Templates.ImageText);
obj.setCellEditable(true);
obj.getSeparatorTemplate().setEvent("ondblclick", function(event){
this.raiseEvent("onSeparatorDoubleClicked", event, this.$0);
});
obj.onSeparatorDoubleClicked = function(event, col){
if (!col) {
return;
}
var maxSize = 0;
var hiddenSpan = document.getElementById("textSize");
for (var i = 0; i < obj.getRowCount(); i++) {
var text = obj.getCellText(col, i);
var textArray = text.split("<BR>");
for (var j = 0; j < textArray.length; j++) {
hiddenSpan.innerHTML = textArray[j];
if (hiddenSpan.offsetWidth > maxSize) {
maxSize = hiddenSpan.offsetWidth;
}
}
}
var text = obj.getHeaderText(col,0);
hiddenSpan.innerHTML = text;
if (hiddenSpan.offsetWidth > maxSize) {
maxSize = hiddenSpan.offsetWidth;
}
obj.setColumnWidth(maxSize+adjustment, col);
}
obj.setSize(800, 500);
document.write(obj);
</script>
<BR>
<span id="textSize" style="font-size:11px;font-family:Tahoma;width:auto;visibility:hidden;white-space:nowrap;"></span>
</body>
</html>
This topic is archived.