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.
(class name /attributes or table/columns )
Employee -id,firstname,lastname,email
Sports - id ,sportname,count
Tropy - id ,result.
If the user select Employee from dropdown , i will pull the data from employee table and show it in datatable.
view Part given below
var table = $('#example').DataTable( {
"sAjaxSource": "/restservice/employee",
"sAjaxDataProp": "",
"order": [[ 0, "asc" ]],
"aoColumns": [
{ "mData": "id"},
{ "mData": "firstName"},
{ "mData": "lastName"},
{ "mData": "email"}
],
"paging":false
});
Given below is Controller
@org.springframework.web.bind.annotation.RestController
public class RestController {
@RequestMapping(path="/restservice/employee", method=RequestMethod.GET)
public List<Employee> getEmployees()
{
List<Employee> employeesList = new ArrayList<Employee>();
employeesList.add(new Employee(1,"khaja","sherif","[email protected]"));
employeesList.add(new Employee(2,"bharathi","bar","[email protected]"));
employeesList.add(new Employee(3,"arun ","arun","[email protected]"));
employeesList.add(new Employee(4,"rajesh","bose","[email protected]"));
return employeesList;
}
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 ?