问题
I am using display tag to display values in a table. I want to color a specific row in the table based on the values in the column say 'Y' then color row with red color. How can i do this? I have been looking up the documentation for display tag which uses decorator class and addRowClass() method, but its too confusing. Is there a method to do this using JavaScript?
回答1:
I've been using the below javascript which I found HERE
<script type="text/javascript">
<!--
var table = document.getElementById("user");
var tbody = table.getElementsByTagName("tbody")[0];
var rows = tbody.getElementsByTagName("tr");
// add event handlers so rows light up and are clickable
for (i=0; i < rows.length; i++) {
var value = rows[i].getElementsByTagName("td")[0].firstChild.nodeValue;
if (value == 'mraible') {
rows[i].style.backgroundColor = "red";
}
}
//-->
</script>
回答2:
You can set decorator="decorator" for your table and override addRowClass method.
request.setAttribute("decorator", new org.displaytag.decorator.TableDecorator() {...});
来源:https://stackoverflow.com/questions/1614283/how-to-decorate-a-row-in-table-using-displaytag