2

I want to dynamically control table style (height, width etc.). My approach is as below:

Controller

public class Cntl_DynamicTableWidth {
    String a{set; get;}
    public Cntl_DynamicTableWidth (){
        a = 'style= "width:100px; height:200px"';
    }
}

VF Page: erroneous

Error: DynamicTableWidth line 3, column 10: Element type "table" must be followed by either attribute specifications, ">" or "/>"
Error Error: Element type "table" must be followed by either attribute specifications, ">" or "/>".

<apex:page controller="Cntl_DynamicTableWidth">
  <table {!a} border="1">
      <tr>
        <th Value="firstCol" >firstCol</th>
        <th Value="firstCol" >firstCol1</th>
      </tr>
      <tr>
        <td Value="firstCol" >firstCol</td>
        <td Value="firstCol" >firstCol</td>
      </tr>
  </table>
</apex:page>

Here I have used table. You may provide solutions with any type of tables like datatable etc.

Please let me know how to correct it..

2

It's failing to compile because it doesn't like the standalone {!a}, but with a small change it should work:

public class Cntl_DynamicTableWidth {
    String a{set; get;}
    public Cntl_DynamicTableWidth (){
        a = 'width:100px; height:200px';
    }
}


<apex:page controller="Cntl_DynamicTableWidth">
  <table style="{!a}" border="1">
      <tr>
        <th Value="firstCol" >firstCol</th>
        <th Value="firstCol" >firstCol1</th>
      </tr>
      <tr>
        <td Value="firstCol" >firstCol</td>
        <td Value="firstCol" >firstCol</td>
      </tr>
  </table>
</apex:page>
  • Only one small change, we need to add PUBLIC: public String a{set; get;} Now it's working absolutely fine. Thanks a ton! – Kamruzzaman Nov 26 '16 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.