title: Dynamic Table using jQuery template
body: <p>I am trying to create a Dynamic Table using jQuery Template plugin.</p>
  
  <p>My requirement is that columns are created dynamically i.e. there is a ListBox with ColumnNames... when item is clicked it should create a table with that column and when another item is clicked it should update the existing template and add the second column and so on...</p>
  
  <p>I am trying with the following code sample but no luck...</p>
  
  <p>Can anyone tell me how can I do it?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;style type="text/css"&gt;
          table
          {
              border-collapse: collapse;
              margin: 8px;
              background-color: #f8f8f8;
              width:600px;
              overflow:scroll;
          }
          table td
          {
              border: 1px solid blue;
              padding: 3px;
          }
      &lt;/style&gt;
      &lt;script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"
          type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;button id="showColBtn"&gt;
          CreateColumn&lt;/button&gt;&lt;br /&gt;
      &lt;table&gt;
          &lt;thead&gt;
              &lt;tr id="tblOrderReportHeaderRow"&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody id="tblOrderReportBody"&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
      &lt;script type="text/javascript"&gt;
  
          var markup = "";
          var arrTableHeader = [];
  
          /* Render the Column Name template */
          $("#showColBtn").click(function () {
              for (var i = 0; i &lt;= 10; i++) {
                  markup += createHeaderMarkup();
                  arrTableHeader.push(createHeader("Col" + i));
              }
              /* Compile markup string as a named template */
              $.template("tblHeaderTemplate", markup);
  
              $("#tblOrderReportHeaderRow").empty();
              $.tmpl("tblHeaderTemplate", arrTableHeader).appendTo("#tblOrderReportHeaderRow");
          });
  
          function createHeaderMarkup() {
              return ("&lt;th colspan='2'&gt;${colName}&lt;/th&gt;");
  
          }
  
          function createHeader(colName) {
  
              return ({ 'colName': colName });
  
          }
  
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>