How to decorate a row in table using displaytag

徘徊边缘 提交于 2020-01-06 11:21:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!