Great, now (I think) I'm understanding better what you're doing.

Is there no way to find out what that .NET-assigned prefix is? That would
let you do a direct #id lookup.

If you can't do that, one thing that will speed up the selectors a lot is to
add the tagname.

Also, it appears that the prefix is the same for the <table> and the <tr>
elements inside it. Is that something you can count on? If so, you could
speed up the selector tremendously:

    var $table = $( 'table[id$=gvBillingHistory]' );
    var prefix = $table[0].id.replace( /gvBillingHistory$/, '' );
    var $target = $( '#' + prefix + 'GPRow_' + GPRowID + ']' );

Using the 'table' tagname in the first selector should make that selector
reasonably fast - it only has to search all of the <table> elements instead
of *every* element.

Then we pick up the prefix from the table's id and use it to construct a
very fast #id selector for $target.

If you can't count on a consistent prefix, you could still speed up the
original selector a lot by simply adding the table and tr tagnames to the
individual selectors:

var $target = $( 'tr[id$=GPRow_' + GPRowID + ']',
'table[id$=gvBillingHistory]' );

Either way, put this code outside the loop and that will be one thing out of
the way.

You're right, the next step after that would be to build up an HTML string
and insert it instead of building DOM elements. That can be much faster.

I'm confused on another point, though. When you do the appendTo(), it
appears that you are inserting a <tr> element *inside* another <tr> element.
That can't be right - or did I misread it? I wonder if insertAfter() is what
you wanted instead of appendTo()?

-Mike

> From: Coryt
> 
> Ah, yes, sorry, the @ selectors are because I am using .net, 
> which alters rendered control ID values. Therefore I need to 
> search for the end of the ID.
> From what i read and as you noted, the selector $( 
> "[EMAIL PROTECTED]" + GPRowID + "]", "[EMAIL PROTECTED]" ), 
> would use "[EMAIL PROTECTED] $=gvBillingHistory]"  as its context to 
> search for the first half of the selector "[EMAIL PROTECTED]" + 
> GPRowID + "]". This was supposed to improve the efficiency of 
> the selector, however if this is not the case, I would gladly 
> switch to using a different selector as long as I can still 
> search for the end of a string. Any suggestions?
> 
> As you pointed out, the ID vs id is a mistake, but the *end 
> with* is correct (due to .Net rendering), also I understand 
> what you said about being able to move the selector out of 
> the loop. I assume instead of having the loop append each new 
> row directly into the DOM, I could build a local string, then 
> once the loop finishes, append the string where I need it. I 
> suspect this would improve the performance.
> 
> Here is a snippet of my gvBillingHistory table html:
> <table class="gridview" cellspacing="0" rules="all" border="1"
> id="ctl00_MainContent_gvBillingHistory" style="border- 
> collapse:collapse;">
>       <tr class="gvheader">
>               <th scope="col">&nbsp;</th><th 
> scope="col">Date</th><th scope="col">Doc #</th><th 
> scope="col">Subtotal</th><th scope="col">Tax</th><th 
> scope="col">Total</th><th scope="col">Payment</
> th><th scope="col">GP Status</th>
>       </tr>
>       <tr id="ctl00_MainContent_gvBillingHistory_GPRow_0">
>               <td 
> onclick="GetGPDocumentLineItems('PYM-522873-1',0)" style="width:
> 16px;height:16px;text-align:center;">+</td><td>
>                       09/30/2008
>               </td><td>
>                       PYM-522873-1
>               </td><td>
>                       $0.00
>               </td><td>
>                       $0.00
>               </td><td>
>                       -
>               </td><td>
>                       $8,680.00
>               </td><td>
>                       Posted
>               </td>
>       </tr>
>       <tr id="ctl00_MainContent_gvBillingHistory_GPRow_1" 
> class="dgalt">
>               <td 
> onclick="GetGPDocumentLineItems('INV-522873-3',1)" style="width:
> 16px;height:16px;text-align:center;">+</td><td>
>                       09/30/2008
>               </td><td>
>                       INV-522873-3
>               </td><td>
>                       $1,652.00
>               </td><td>
>                       $84.00
>               </td><td>
>                       $1,736.00
>               </td><td>
>                       -
>               </td><td>
>                       Posted
>               </td>
>       </tr>
> </table>
> 

Reply via email to