Re: [displaytag-user] is there a way...
Brought to you by:
fgiust
From: Kyle A. <ka...@gf...> - 2006-05-24 18:56:12
|
Scott, Take a look at the idea of unobtrusive javascript: http://www.onlinetools.org/articles/unobtrusivejavascript/ Basically the idea is that you keep javascript-related stuff like onmouse* out of the HTML code, and attach the appropriate eventhandlers to the HTML element's class or ID (both of which are configurable in displaytag). Classes should be used when you want to apply something to multiple elements in your page; IDs when you want to apply to only one uniquely identified element. In your case I'd use a class because it would allow us to attach onmouse* events to multiple tables within a page. <display:table class="stripe" ... > ... </display:table> Resulting HTML: <table class="stripe" ... > ... </table> I could go into a long and detailed description of how to code the JS, but someone's already done the hard work of implementing the highlighting you're looking for: http://validweb.nl/artikelen/javascript/better-zebra-tables/ There are a couple of modifications you might want to make to that script. It will stripe all tables at the current moment. If you want it to only stripe tables with a class of "stripe" (or whatever), you'll want to look at using the jQuery ( http://jquery.com/ ) library to make the following change: var tables = document.getElementsByTagName("table"); to: var tables = $("table.stripe"); If you want multiple events to be triggered when the document loads, you'll have to use a full-featured event handler library. I'd recommend Yahoo's Event library ( http://developer.yahoo.com/yui/event/ ). You'll have to change: window.onload = stripe; to: YAHOO.util.Event.addListener(window, "load", stripe); Finally, notice that all the javascript does is add/subtract classes to the table rows in question. The actual appearance of the striping is controlled by the styles defined for the classes in CSS files. This is consistent with unobtrusive javascripting (AKA DOM scripting), which separates markup (HTML) from behavior (JS) from presentation (CSS). Probably not the straightforward answer you were hoping for, but your web development will go much smoother once you get the hang of unobtrusive javascripting. The long term rewards are well worth the initial investment. Kyle _____ Kyle Adams | Java Developer | Gordon Food Service | 616-717-6162 |