Menu

How to add "id" attribute to <TR>

2004-12-28
2012-10-09
  • Mohamed Zafer

    Mohamed Zafer - 2004-12-28

    Is their a possibility to add the id attribute to the <TR> and assign a value from java to it. Actaully I need to display/ hide the row dynamically using javascript and I need the 'id' attribute for that. Any help will be greatly appreciated.

    Thanks
    Zafer

     
    • ms

      ms - 2005-07-01

      has anyone managed to solve this problem? i also need to add an ID attribute to each <TR> element of the table to allow dynamic row selection using Javascript.

       
      • Jatin

        Jatin - 2007-01-10

        Yea.. I have done this.. Actually.. it wld be better if u override addRowId method of display tag,Performce wise it wld b better than javascript.I am giving both the examples u can use any1 of ur choice..

        Override addRowID()

        <%request.setAttribute("dyndecorator", new org.displaytag.decorator.TableDecorator()
        {
        public String addRowId()
        {
        return "" + evaluate("rowId");
        }

                                             });
                                           %&gt;
        

        Here they have use concept of inner class rowID is any property u want to keep as id which wld b unique.. if not then set a bean property as a counter..just mention display:table decorator ="dyndecorator"

        Using jaavscript
        Thsi is however simple to understand bt u can check the perforemace.Basically this function wld go in onload f the page.
        where detailRow is the id of the display table id attribute

        var tab=document.getElementById('detailRow');
        if(tab!=null){
        var tbody = tab.getElementsByTagName("tbody")[0];
        var tabRows=tbody.getElementsByTagName("tr");

                for(var i=0;i&lt;tabRows.length;i++){
                    var row=tabRows.item(i);
                    var check=row.getElementsByTagName(&quot;input&quot;)[0];
                    var rowId=check.value;
                    row.setAttribute(&quot;id&quot;,rowId);
            }
             }
        
         

Log in to post a comment.

MongoDB Logo MongoDB