O
Oltmans
Hello all,
I'm dealing with <table> and <tr>s here and I've a function that takes
two arguments, one is the array of strings(containing <tr> ids e.g. if
we have <tr id="hello"> then our string array might contain 'hello'---
please hold on , let me explain a bit and I'm sure it will make some
sense) and other argument is the table id, which in my case is
"myTable". Now in this function I've to loop through all TRs (rows) in
this table and find those TRs whose value matches with IDs contained
in our other argument i.e. array of strings containing IDs). Here is
how my function looks like
------------------------------------------------------------------------------------
function findRows(idStringArray, tableID)
{
var
rows=document.getElementById("myTable").getElementByTagsName("tr");
var table=document.getElementById("myTable");
for (var i=0; i<idStringArray.length; i++)
{
for (var j=0; j<rows.length;j++)
{
if ( rows[j].ID == idStringArray )
//Got the row, can now do anything with it. So we have to
store all such rows
//whose ID matches with any of the ID given in
idStringArray
}
}
}
Now problem is that I've huge number rows in a table and the above
code is taking too much time. My code above is taking some time and I
need to optimize this. Any ideas on how should I optimize this code?
Please enlighten me, I will appreciate your feedback.
Thanks,
Oltmans
I'm dealing with <table> and <tr>s here and I've a function that takes
two arguments, one is the array of strings(containing <tr> ids e.g. if
we have <tr id="hello"> then our string array might contain 'hello'---
please hold on , let me explain a bit and I'm sure it will make some
sense) and other argument is the table id, which in my case is
"myTable". Now in this function I've to loop through all TRs (rows) in
this table and find those TRs whose value matches with IDs contained
in our other argument i.e. array of strings containing IDs). Here is
how my function looks like
------------------------------------------------------------------------------------
function findRows(idStringArray, tableID)
{
var
rows=document.getElementById("myTable").getElementByTagsName("tr");
var table=document.getElementById("myTable");
for (var i=0; i<idStringArray.length; i++)
{
for (var j=0; j<rows.length;j++)
{
if ( rows[j].ID == idStringArray )
//Got the row, can now do anything with it. So we have to
store all such rows
//whose ID matches with any of the ID given in
idStringArray
}
}
}
Now problem is that I've huge number rows in a table and the above
code is taking too much time. My code above is taking some time and I
need to optimize this. Any ideas on how should I optimize this code?
Please enlighten me, I will appreciate your feedback.
Thanks,
Oltmans