title: Dynamically construct jquery datatable with server side data
body: <p>Based on the parameter , i would like to load the database table data into jquery datatable for CRUD operation . Please suggest me how to construct the table header based on the parameter.</p>
  
  <pre><code>(class name /attributes or table/columns ) 
  Employee -id,firstname,lastname,email
  Sports  - id ,sportname,count
  Tropy   - id ,result.
  </code></pre>
  
  <p>If the user select Employee from dropdown , i will pull the data from employee table and show it in datatable.</p>
  
  <p>view Part given below</p>
  
  <pre><code>var table = $('#example').DataTable( {
          "sAjaxSource": "/restservice/employee",
          "sAjaxDataProp": "",
          "order": [[ 0, "asc" ]],
            "aoColumns": [
              { "mData": "id"},
              { "mData": "firstName"},
              { "mData": "lastName"},
              { "mData": "email"}
            ],
            "paging":false
          });
  </code></pre>
  
  <p>Given below is Controller</p>
  
  <pre><code>@org.springframework.web.bind.annotation.RestController
  public class RestController {
  
       @RequestMapping(path="/restservice/employee", method=RequestMethod.GET)
          public List&lt;Employee&gt; getEmployees() 
          {
  
              List&lt;Employee&gt; employeesList = new ArrayList&lt;Employee&gt;();
              employeesList.add(new Employee(1,"khaja","sherif","khaja@gmail.com"));
              employeesList.add(new Employee(2,"bharathi","bar","bharathi@gmail.com"));
              employeesList.add(new Employee(3,"arun ","arun","arun@gmail.com"));
              employeesList.add(new Employee(4,"rajesh","bose","rajesh@gmail.com"));
              return employeesList;
          }
  </code></pre>
  
  <p>Employee table contains 4 columns, so i have hardcoded 4 column in datatable.
  Since sports and trophy contains 3 and 2 column respectively , how to construct the table header in datatable ?</p>