• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

slow for loops inside javascript..

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my main javascript function first calls the showColumns() method & then calls the hideColumns method..columns are not displayed depending upon the value in myArray(1-hideColumn && other-displayColumn)..The use of these 'for loops' slows down the output drastically....is there a way out??!! I am wondering if there iz a way to eliminate the inner for loop which finds each row & deletes it...iz there a simpler method where we could delete the entire column at one shot ??? help grtly appreciated....


function showColumns(table)
{
for(var m=0; m<colLength; m++)
{
for (var r=0; r<rowSize; r++)
{
table.rows[r].cells[m].style.display = '';
}
}
}

function hideColumns(myArray, table)
{
for(var cols=0 ; cols<colLength; cols++)
{
if(myArray[cols] == '1')
{
for (var r=0 ; r<rowSize ; r++)
{
table.rows[r].cells[cols].style.display = 'none';
}
}
}
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a trick that you can do with CSS, should work with almost all modern day browsers.

You can apply style sheet rule to the cells that are to be hidden
class="showHideCell"

Then you need to create two style sheets that have the same rule, but one has

other has


Add the style sheets and make sure that they are the first 2 style sheets listed.

Note: The disabled property does not apply the rules

You then can toggle the style sheets on or off to show or hide the column


This should work, I am too busy to make a running example.

Eric
 
Sarran Vidyakumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey eric/guyz:
i tried something along those lines on a huge sample data & it definetely works faster than looping in javascript...but I still have a problem in that when dealing with huge amount of rows/columns the checkboxes which I use to show/hide columns dont work correctly...they get a grey shade && do not get checked/unchecked as soon as we click on it...in fact it takes the same amount as the column showing/hiding operation....as in if i need to hide 20 columns & i uncheck a box the sign disappears only after the 20 columns have been removed...even other checkboxes get disabled during this time ???
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are going to run into these problems since JavaScript is not made to handle tons of data. The whole process is dependent on the speed of your computer.

How can you made it perform bet? You can cut the data down in sections with paging. There is no other way to avoid slowness.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an example of what I did in similar case.
The idea is to proccess some amount of rows in once with some small interval, so the page will not be frozen during the long loops. You can add some inteligence to that in order to always start with the rows that currently visible.

In the following code once you call doAction, it will start a loop, proccesing 10 rows at a time with 10 ms interval.

 
Sarran Vidyakumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey guyz:
i completed the above with xsl & itz super fast compared to javascript...
 
reply
    Bookmark Topic Watch Topic
  • New Topic