function fixCatTableWidth(tableID, sizeArray, tableSize) {
// Reset the outer table width
var outer = dojo.byId(tableID+"_OUTER_TABLE");
if (tableSize == null || tableSize == "") {
outer.style.width = "100%";
} else {
outer.style.width = tableSize;
}
var max = sizeArray.length;
// Get the table and all header elements
var table = dojo.byId(tableID);
var allHeaders = table.getElementsByTagName("th");
var maxHeaders = allHeaders.length;
for (i=0;i<maxHeaders;i++) {
var curWidth = (i > max) ? sizeArray[max] : sizeArray[i];
allHeaders[i].style.width = curWidth;
}
}
/**
* Finds for a given element inside a table hierarchy the table data
* element it is contained in
**/
function getEnclosingTdTag(startElement) {
var parent = startElement.parentNode;
while (parent != null) {
if (parent.tagName == "td" || parent.tagName == "TD") {
break;
}
parent = parent.parentNode;
}
return parent;
}
/**
* Gets all categorized rows and replaces empty td with colspan
**/
function fixCatTableSpan(tableID) {
var tbl = dojo.byId(tableID);
var allButtons = tbl.getElementsByTagName("button");
var max = allButtons.length;
for(i=0; i<max;i++) {
var curButton = allButtons[i];
if (curButton.title == "collapsed" || curButton.title == "expanded") {
//We need to process it
var curTD = getEnclosingTdTag(curButton);
if (curTD != null) {
replaceEmptyTdWithColSpan(curTD);
}
}
}
}
/**
* Finds all empty td tags after a given start tag and removes them
* also inserts the colspan attribute into the start tag
**/
function replaceEmptyTdWithColSpan(startElement) {
// No action needed if colspan is aleady > 1
if (startElement.colSpan > 1) {
return;
}
var colSpan = 1;
var nextSibling = startElement.nextSibling;
while (nextSibling != null) {
var following = nextSibling.nextSibling;
if (nextSibling.nodeName == "TD") {
// We stop at the first non empty node
if (nextSibling.firstChild == null) {
nextSibling.parentNode.removeChild(nextSibling);
colSpan +=1;
} else {
break;
}
}
nextSibling = following;
}
if (colSpan > 1) {
startElement.colSpan = colSpan;
}
}
Comments
or is that the though behind it?
Posted by Patrick Kwinten At 19:09:04 On 07/16/2010 | - Website - |
Posted by Stephan H. Wissel At 23:26:09 On 07/16/2010 | - Website - |