title: dynamically set table titles with jquery's Datatables plugin - get titles from data object
body: <p>Im searching for a way to set tables titles dynamically.
  there's a search form that performs database queries, and gets a different data-set each time, according to user choice.</p>
  
  <p>right now titles are hard-coded in the html.</p>
  
  <p>this is how I set up the table:</p>
  
  <pre><code>&lt;table id="searchResults" class="display table table-striped table-bordered" cellspacing="0" width="100%"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;agentId&lt;/th&gt;
        &lt;th&gt;confirmTime&lt;/th&gt;
        &lt;th&gt;name&lt;/th&gt;
        &lt;th&gt;amount&lt;/th&gt;
        &lt;th&gt;currency&lt;/th&gt;
        &lt;th&gt;amountUSD&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
  
    &lt;tfoot&gt;
      &lt;tr&gt;
        &lt;th&gt;agentId&lt;/th&gt;
        &lt;th&gt;confirmTime&lt;/th&gt;
        &lt;th&gt;name&lt;/th&gt;
        &lt;th&gt;amount&lt;/th&gt;
        &lt;th&gt;currency&lt;/th&gt;
        &lt;th&gt;amountUSD&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/tfoot&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>javascript:</p>
  
  <pre><code>Api.getDeposits(formData).then(function(res){
    $('#searchResults').dataTable( {
        "data": res,
        "scrollX": "100%",
        "columns": [
            { "data": "agentId" },
            { "data": "confirmTime" },
            { "data": "name" },
            { "data": "amount" },
            { "data": "currency" },
            { "data": "amountUSD" }
        ]
    });
  });
  </code></pre>
  
  <p>sample data:</p>
  
  <pre><code>[{
    "agentId": 70,
    "amount": 250,
    "amountUSD": 250,
    "confirmTime": "2015-04-28 10:49:00",
    "currency": "USD",
    "email": "name@mail.ru",
    "name": "some name",
    "paymentMethod": "Credit Card",
    "status": "approved"
  }]
  </code></pre>
  
  <p>I'd like to set tfoot, thead, according to the data I get from the server, 
  so I only have one template for many situations</p>