/    Sign up×
Community /Pin to ProfileBookmark

Every other table row

I recently posted a question regarding alternate table row colors and needing it to apply to all displayed rows (not hidden rows).

I received a wonderful response and all was well.

Although I am working on a loose implementation of the code from this site: [url]http://www.vonloesch.de/node/23[/url]

I love the way it searches/highlights. I don’t need anything complex done here, in fact it is almost identical to the needs of my last post.

I wanted to run that script on every other table row. The problem is rows in my project are expanding, so the second row in each set has ALOT of info, so the script stalls out. I just want to skip those rows.

So I just wanted to run it on every other row if possible.

Any help would be greatly appreciated!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@FangAug 30.2007 — Could you give an example of the table and what should be highlighted?
Copy linkTweet thisAlerts:
@jbuddyauthorAug 30.2007 — Sure. The rows are built via XSL but here is where it all starts:

[CODE]
<xsl:template match="data">
<table name="t1" id="t1" >
<xsl:apply-templates select="book[($data1='all') or ($data1=./genre)]">
<xsl:sort select="title"/>
</xsl:apply-templates>
</table>
</xsl:template>

<xsl:template match="this_data">
<tr class="alt_row_color{position() mod 2}" onclick="showindepth_onclick(this);">
<td><xsl:value-of select="position()"/></td>
<td><xsl:value-of select="data1"/></td>
<td><xsl:value-of select="data2"/></td>
<td><xsl:value-of select="data3"/></td>
<td><xsl:value-of select="data4"/></td>
<td><xsl:value-of select="data5"/></td>
</tr>
<tr> <td> ALL MY CONTENT </td></tr>
</xsl:template>
[/CODE]


I removed much of the obvious stuff (title, actual values, etc..).

So basically XSL builds the table rows for me. It creates the main header row with all of the data, once the user clicks the row it expands to show the in depth data.

The second row is where this "in depth" data will be located. I don't want it to search through the "in depth" rows ( <tr> <td> ALL MY CONTENT </td></tr>).

So I simply need the script to access each header row, and skip the in depth rows, for lack of a better term. So really, every other row.

Let me know if this helps explain what I am after.

Oh and as far as highlighting, the user puts their search term in a textbox and hits a "search" button which runs the script. Which then highlights the term, if it exists, in each header row (or at least ideally).

And thank you for the help!!
Copy linkTweet thisAlerts:
@FangAug 30.2007 — If the cells contain only text, then this snippet should highlight the header row:var rowList=document.getElementById('t1').getElementsByTagName('tr');
for(var i=0; i&lt;rowList; i++) {
if(!rowList[i].getAttribute('class') &amp;&amp; /searchExpression/.test(rowList[i].getElementsByTagName('td')[0].firstChild.data) ) {
rowList[i-1].className='highlight';
}
}
Copy linkTweet thisAlerts:
@jbuddyauthorSep 04.2007 — I am not new to Javascript by any means, though wouldn't call myself an expert either. I would be a knowledgable newbie at best...heh

So this particular portion has had me confused for days:

[CODE]&& /searchExpression/.test[/CODE]

I am just not sure how I should work this in there?

Could you give a quick example if possible>?

I have a feeling what you have done will work just fine, providing I could figure out how to implement it correctly.

Thank you for all the help!
Copy linkTweet thisAlerts:
@FangSep 04.2007 — [I]searchExpression[/I] is the text you are looking for.

[I]test[/I] attempts to find that expression in a cell.

http://www.javascriptkit.com/javatutors/redev3.shtml
Copy linkTweet thisAlerts:
@jbuddyauthorSep 04.2007 — Forgive me.. from time to time I think we all draw a blank.

What is funny is I just wrote a paper on regexp (a very simple paper) and how its used. I didn't even consider this when looking at the above.

Ill give it another go and will you let you know if I was successful.

Thank you for clearing that up.
×

Success!

Help @jbuddy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...