这里我试图在jqueryData中加载数据表格在tabler中显示数据格式它在Json中显示喜欢
{"iTotalRecords":12,"aaData":[{"Emp_Id":101,"EmpName":"Hussain","Email":"Hussain@gmail.com","Psw":null,"Cnt_Id":0,"Cnt_Name":"India","Sts_Id":0,"Sts_Name":"Telangana","City_Id":0,"City_Name":"Hyd","dept_ID":null,"Date":"\/Date(1420050600000)\/","sal":15000,"Gen_Id":null,"Gen_Name":null}]}
Mvc代码
public ActionResult Index()
{
var x = ObjRepo.GetEmployees(1);
int size =ObjRepo.CountEmployee();
return Json(new { iTotalRecords = size, aaData }, JsonRequestBehavior.AllowGet);
}
Jquery的
$(document).ready(function () {
$('#table_id').dataTable({
//Here i Hotcoded my data Even imm not dusplay data
"iTotalRecords":12,"aaData":[{"Emp_Id":101,"EmpName":"Hussain","Email":"Hussain@gmail.com"
}],
"processing": true,
"serverSide": true,
"Columns": [
{ 'data': 'Emp_Id' },
{ 'data': 'EmpName' },
],
});
})
答案 0 :(得分:1)
您可以在function
或document ready
..
$.ajax({
type: 'GET',
url: '@Url.Action("GetEmployees", "ControllerName")',
cache: false,
success: function (result) {
$("#table_id").DataTable({
destroy: true,
data: result,
columns: [
{ data: 'employee_id' },
{ data: 'employee_name' }
]
});
}
});
然后您需要在thead
#table_id
的html表格
控制器:
[HttpGet]
public ActionResult GetEmployees()
{
var x = ObjRepo.GetEmployees(1);
int size =ObjRepo.CountEmployee();
return Json(new { iTotalRecords = size, aaData }, JsonRequestBehavior.AllowGet);
}