More information on this topic is available in the documentation section: /active.howto.style.columns/column-width.html.
<style id='gridStyle'>
give your style sheet an id tag so we can get to it later.var colSizes = new Array(myColumns.length) // array for colwidths
for (h=0;h<myColumns.length;h++){ // intialize with header widths
colSizes[h]= myColumns[h].length;
}
//get data function sets the col width for th
//data column if it is greater than the stored
//width
function getData(i, j){
chars = myData[i][j].length;
if ( chars > colSizes[j]) {
if (chars<70) { //70 char max to stop really wide cols.
colSizes[j] = chars;
} else {
colSizes[j] = 70;
}
}
return myData[i][j]
}
grid.setProperty("data/text", getData);
document.write(grid);
var ssheet = document.getElementById("gridStyle").styleSheet;
for( cs=0;cs<myColumns.length-1;cs++) {
ssheet.addRule(".active-column-"+cs, "width:"+((colSizes[cs]*6)+20)+'px');
}
grid.getTemplate("layout").action("adjustSize");
the ((colSizes[cs]*6)+20)+'px') code is an approximation I find works pretty well basically it allows 6pixels per character and 20pixels for safety.var columnA = new Active.Templates.Text;
columnA.setStyle('width', newSize+'px');
gridasGridObj.setTemplate('column', columnA, ndx);
but it does not resize the title, only the cellswhile( document.getElementById( tableid +".data.item:"+ row + ".item:" + ndx ) ){
arr[row] = document.getElementById( tableid +".data.item:"+ row + ".item:" + ndx );
row++;
}
This will be useful for editors etc..for(var i=0; i<colArr.length; i++){
colArr[i].style.width = "auto";
var imax = colArr[i].offsetWidth;
colArr[i].style.width = "";
maxx = (typeof(imax)=="number" && imax>maxx) ? imax : maxx;
}
i also tried:var nodeX = document.body.appendChild(nX);
for(var i=0; i<colArr.length; i++){
nodeX.innerHTML = colArr[i].innerHTML;
var imax = nodeX.offsetWidth;
maxx = (typeof(imax)=="number" && imax>maxx) ? imax : maxx;
}
document.body.removeChild(nodeX);
this was only faster by assigning a display:none;, but you guessed the sideeffect: maxx=0!!!var stylesheet = document.styleSheets[document.styleSheets.length-1];
stylesheet.addRule(".active-column-2", "width:150px");
Actually you also have to add control id if you want to handle more than one grid on the same page. Look at the source code for startColumnResize function in /lib/controls.grid.jsvar header = obj.getTemplate("top/item");
header.getContent("div").setEvent("onclick", function(){
alert(1);
});
I am not sure why doubleclick doesn't work the same way - maybe mousedown event cancels it - however somehow you did it in your code.var row = new Active.Templates.Row;
row.setEvent("ondblclick", function(){this.action("_DoubleClick");}); obj.setAction("_DoubleClick", rowDoubleClick);
row.setEvent("oncontextmenu", rowRightClick);
obj.setTemplate("row", row);
obj.setAction("click", rowClick);
function rowClick (src) {
alert('Single Click on: '+src.getProperty("item/index"));
}
function rowRightClick (src) {
showPopup(event);
}
function rowDoubleClick (src) {
alert('Double Click on: '+src.getProperty("item/index"));
}
I've got to admit. I've tried to use the right click more than the single click since there really is a default action of row selection on the single click already. It's worked for me though to capture both the click and double click.// dynamic column width
$records = mysql_numrows($data);
for($i=0; $i < $records; $i++) {
$row = mysql_fetch_row($data);
$length = mysql_fetch_lengths($data);
foreach($length as $key => $value) {if($maxlength[$key] < $value) {$maxlength[$key] = $value;} }
}
mysql_data_seek($data,0);
$min_col_length = 30;
print "<style>";
foreach($maxlength as $key => $value) {if($value * 10 < $min_col_length) {print".active-column-$key {width:" . ($min_col_length) . "px}";} else {print".active-column-$key {width:" . ($value * 10) . "px}";}}
print "</style>";
