Fontzter wrote:
I am trying to implement Excel-like functions on an html table.  Some
of the cells are static and contain calculations and some have input
boxes in them.  The change event of the input boxes fires a
recalculation function.  This function does some Excel-like
calculations on the table data.  I am using Dan Switzer's calculation
plug-in that works wonderfully.  However, the calculations are fairly
complex and the process is too slow.

If the calculations are too slow, I don't know that there's much help to offer. If the problem is that the UI is unresponsive while the calculations take place, there might be some useful tricks involving setTimeout().


The trick is to keep your overall loop variables and loop boundaries in some broad scope and then use a smaller loop inside a timeout, perhaps looping on each row to process, something like this:

    var MAX_ROWS = // find through jQuery or hard-coded or whatever
    var row = 0;

    var processCol = function() {
        for (var col = 0; col < MAX_COLS; col++) {
            // process cell(row, col)
        }
        row++;
        if (row < MAX_ROWS) {
            setTimeout(processCol, 0);
        }
    }

    setTimeout(processCol, 0);

This allows for a responsive UI because in between the setTimeout calls, the browser can perform whatever other functions it needs to.

But as I said, if it's the calculations themselves causing problems, then I don't really have a suggestion without seeing the actual calculations.

Good luck,

  -- Scott Sauyet

Reply via email to