C_J_L
asked on
Hiding columns load performance
We have a hide column function that takes a long time to load the data. TECHNIQUE 1 below is slightly faster than TECHNIQUE 2 but they are both too slow. Any suggestions on how to increase the load performance for hiding columns?
function hideColumn(count,str) {
var layoutName = getLayoutName(count);
if (layoutName == false) return false;
var tableLayout = document.getElementById(la youtName + "-table");
if (!tableLayout) return;
var col = -1;
//Find the column with str as its header
for (var c=0; c<tableLayout.rows[0].cell s.length; c++) {
var str1 = tableLayout.rows[0].cells[ c].innerTe xt;
//strip trailing blanks
while (str1.substring(str1.lengt h-1,str1.l ength) == ' ') str1 = str1.substring(0,str1.leng th-1);
if (str1 == str) {
col = c + 1;
break;
}
}
if (col < 0) return;
var maxRow;
if (footRow > -1 ) {
maxRow = footRow - 1;
} else if (aggrRow > -1 ) {
maxRow = aggrRow;
} else {
maxRow = tableLayout.rows.length;
}
for (var row = 1; row<=maxRow; row++) {
// tableLayout.rows[row-1].de leteCell(c ol-1); //TECHNIQUE 1
tableLayout.rows[row-1].ce lls(col-1) .style.dis play='none '; //TECHNIQUE 2
}
}
function hideColumn(count,str) {
var layoutName = getLayoutName(count);
if (layoutName == false) return false;
var tableLayout = document.getElementById(la
if (!tableLayout) return;
var col = -1;
//Find the column with str as its header
for (var c=0; c<tableLayout.rows[0].cell
var str1 = tableLayout.rows[0].cells[
//strip trailing blanks
while (str1.substring(str1.lengt
if (str1 == str) {
col = c + 1;
break;
}
}
if (col < 0) return;
var maxRow;
if (footRow > -1 ) {
maxRow = footRow - 1;
} else if (aggrRow > -1 ) {
maxRow = aggrRow;
} else {
maxRow = tableLayout.rows.length;
}
for (var row = 1; row<=maxRow; row++) {
// tableLayout.rows[row-1].de
tableLayout.rows[row-1].ce
}
}
I see find the column and hide all it's cells...
Instead of finding the str can you just set the colum's id to that string and use getElementByid instead?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>Instead of finding the str can you just set the colum's id to that string and use getElementByid instead?
That part runs very fast. The slow part is the hiding or deleting of the cells.
The table has no cols or col groups defined. The table must be formatted via javascript as it is already generated and I manipulate it after the fact. I wish I had access to the html but I don't.
How would I create columns and group for this table using javascript?:
<table id="Layout1-table" class=SAPBEXCellspacing cellSpacing=1 cellPadding=0 border=0 >
<tr id="Layout1-1-row">
<td id="Layout1-1-1-cell" colspan="1" nowrap class="SAPBEXchaText">
<span id="Layout1-1-1" ct="TextView" class="urTxtStd urVt1" style="white-space:nowrap; ">Budget Group Code</span></td>
There are 38 more td's following this one for a total of 39 columns. They would be hidden one at a time, if any.
Also, if I use a col group and set atomicselection to true, it will run slow (according to MSDN Library). But I don't know what slow is compared to what it is doing right now.
That part runs very fast. The slow part is the hiding or deleting of the cells.
The table has no cols or col groups defined. The table must be formatted via javascript as it is already generated and I manipulate it after the fact. I wish I had access to the html but I don't.
How would I create columns and group for this table using javascript?:
<table id="Layout1-table" class=SAPBEXCellspacing cellSpacing=1 cellPadding=0 border=0 >
<tr id="Layout1-1-row">
<td id="Layout1-1-1-cell" colspan="1" nowrap class="SAPBEXchaText">
<span id="Layout1-1-1" ct="TextView" class="urTxtStd urVt1" style="white-space:nowrap;
There are 38 more td's following this one for a total of 39 columns. They would be hidden one at a time, if any.
Also, if I use a col group and set atomicselection to true, it will run slow (according to MSDN Library). But I don't know what slow is compared to what it is doing right now.
ASKER
Thanks! I was able to get the getElementById which made it run faster.
//Find the column with str as its header
this i 0(n2) why is it needed? what are you tring to do here?