Thursday, 18 December 2014

Genarating Dynamic Html Table from Apex




 How we can create the html table from Apex Dynamically .?



Visual Force Page 

<body onload ="loadData()">
    <script type ="text/javascript">
        function loadData()
         {
           alert("hi");
           document.getElementById("dynamictable").innerHTML ='{!tableData}';
         }
    </script>
  <div id="dynamictable">
 </div>
</body>


Controller Code 

public class Test_Ctrl
{

        public String tableData { get; set; }
        public Test_Ctrl() {
tableData = '<table bordercolor="#FFCC00" border="1" width="300" cellpadding="3" cellspacing="3" > ';   
        String Sample='Sample Data';
        for(integer i = 0; i <8; i++)
        {
           String str = '<tr>' +
                          '<td colspan="4" align="center">' + Sample +'</td></tr>' ;
                         
           tableData = tableData + str ;
        }
   
          tableData += '</table>';
         //  getAccounts();
        
          System.debug('******tableData *******'+tableData );
        }
}


No comments:

Post a Comment