JQuery Looping Through TableRows

I have a function that is called on document.ready, which goes through a table with approximately 600 rows that was generated in classic ASP. In a "modern" browser (Chrome, Firefox, IE9 Beta) it works for less than 1.5-2 seconds. In IE6, it works after about 5-7 seconds, and not well.

Basically what I am doing is adding the value of the cells to certain columns and giving subtotals. (I know this should be created on the server side, but some brainiac designed this using views that call views, which are called views, which are called views ...).

I used the IE9 profiler to try to understand where the neck of the bottle is, and it seems to be the deepest when jQuery finds and calls each:

tr.find("td").each(function() {
&
tr.find("td").eq(ci).html(tot).css

I will send all the code if necessary, but I was wondering if there is a more efficient way to iterate over rows and cells without a name?

The table looks like this:

32     47       0/0 0 8 1 1                 
32     47  -7   0/0 0 0   7 
Totals     -7   0/0   8 1 8  
32     47       0/0 0 2 1 1                 
32     47  -7   0/0 0 3   7 
Totals     -7   0/0   5 1 8  

I go through the rows of the table, and if I find (td: first) = "Totals", then I put the current tr and the two previous tr into variables, then grab the cells and calculate the resulting values, and place them in the appropriate cells.

It all works, but, as I said, there is a serious neck of the bottle during the search and everyone.

+3
source share
1 answer

, , jQuery - , . javascript , :

var rows = document.getElementById('your-table').rows;
var num_rows = rows.length;
for (var i = 0; i < num_rows; ++i) {
    var cells = rows[i].cells;
    if (cells[0].innerHTML == 'Totals') {
       var num_cells = cells.length;
       for (var j = 1; j < num_cells; ++j) {
           cells[j].innerHTML =
               (parseInt(rows[i-2].cells[j]) || 0) +
               (parseInt(rows[i-1].cells[j]) || 0);
       }
    }
 }
+4

Source: https://habr.com/ru/post/1775745/


All Articles