performance problem looping through table rows

Posted by Sridhar on Stack Overflow See other posts from Stack Overflow or by Sridhar
Published on 2010-04-04T04:31:31Z Indexed on 2010/04/04 4:33 UTC
Read the original article Hit count: 527

Filed under:
|

Hi,

I am using jquery to loop through table rows and save the data. If the table has 200 rows it is performing slow. I am getting the javascript message "Stop Running this script" in IE when I call this method. Following is the code I am using to loop through table rows. Can you please let me know if there is a better way to do this.

    function SaveData() {
    var $table = $('#' + gridid);
    var rows = $table.find('tbody > tr').get();
    var transactions = [];        
    var $row, empno, newTransaction, $rowChildren;
    $.each(rows, function(index, row) {
        $row = $(row);                 
        $rowChildren = $row.children("td");        
        if ($rowChildren.find("input[id*=hRV]").val() === '1') {
            empno = $rowChildren.find("input[id*=tEmpno]").val();
            newTransaction = new Array();            
            newTransaction[0] = company;            
            newTransaction[1] = $rowChildren.find("input[id*=tEmpno]").val();
            newTransaction[2] = $rowChildren.find("input[id*=tPC]").val();
            newTransaction[3] = $rowChildren.find("input[id*=hQty]").val();
            newTransaction[4] = $rowChildren.find("input[id*=hPR]").val();
            newTransaction[5] = $rowChildren.find("input[id*=tJC]").val();
            newTransaction[6] = $rowChildren.find("input[id*=tL1]").val();
            newTransaction[7] = $rowChildren.find("input[id*=tL2]").val();
            newTransaction[8] = $rowChildren.find("input[id*=tL3]").val();
            newTransaction[9] = $rowChildren.find("input[id*=tL4]").val();
            newTransaction[10] = $rowChildren.find("input[id*=tL5]").val();
            newTransaction[11] = $rowChildren.find("input[id*=tL6]").val();
            newTransaction[12] = $rowChildren.find("input[id*=tL7]").val();
            newTransaction[13] = $rowChildren.find("input[id*=tL8]").val();
            newTransaction[14] = $rowChildren.find("input[id*=tL9]").val();
            newTransaction[15] = $rowChildren.find("input[id*=tL10]").val();
            newTransaction[16] = $rowChildren.find("input[id*=tSF]").val();
            newTransaction[17] = $rowChildren.find("input[id*=tCG]").val();
            newTransaction[18] = $rowChildren.find("input[id*=tTF]").val();
            newTransaction[19] = $rowChildren.find("input[id*=tWK]").val();
            newTransaction[20] = $rowChildren.find("input[id*=tAI]").val();
            newTransaction[21] = $rowChildren.find("input[id*=tWC]").val();
            newTransaction[22] = $rowChildren.find("input[id*=tPI]").val();
            newTransaction[23] = "E";

            var record = newTransaction.join(';');
            transactions.push(record);    
        }        
    });
    if (transactions.length > 0) {
        var strTransactions = transactions.join('|');
        //send data to server
        //here ajax function is called to save data.
    }
}

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript