Jquery 数据表标题
已解决,请参见下文 我更改了我的html文件,使其包含这样的标题名,并删除了javascript文件中的列声明。如果有人愿意,也会发布javascript文件Jquery 数据表标题,jquery,datatables,Jquery,Datatables,已解决,请参见下文 我更改了我的html文件,使其包含这样的标题名,并删除了javascript文件中的列声明。如果有人愿意,也会发布javascript文件 <table id="example" class="display" cellspacing="0"> <thead> <tr> <th>User ID</th> &
<table id="example" class="display" cellspacing="0">
<thead>
<tr>
<th>User ID</th>
<th>Name</th>
<th>Active</th>
<th>Email</th>
<th>Type</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Phone</th>
<th>Shirt Size</th>
<th>Company Name</th>
<th>Member Since</th>
</tr>
</thead>
</table>
用户ID
名称
活跃的
电子邮件
类型
地址
城市
陈述
邮政编码
电话
衬衫尺码
公司名称
成员自
我正在尝试让DataTables在我的站点上工作。我已经正确显示了我的数据,但由于某些原因,我的标题不会出现。数据数组是正确的。我尝试过在这个链接上建议的东西,但没有成功
以及
如何让标题显示?可能是因为太多了吧
$(document).ready(function () {
var userData = [];
$.ajax({
type: "GET",
url: "/api/User",
contentType: "application/json",
}).done(function (d) {
var userArray = [];
//console.log(d);
for (i = 0; i < d.length; i++) {
userData[i] = [];
userData[i].push(d[i].id, d[i].isActive, d[i].name, d[i].email, d[i].type, d[i].address,
d[i].city, d[i].state, d[i].zip, d[i].phone, d[i].tshirtSize, d[i].companyName, d[i].dateCreated);
}
console.log(userData);
$('#example').DataTable({
"aaData": userData,
"aoColumns": [
{ title: "User ID" },
{ title: "Active" },
{ title: "Email" },
{ title: "Type" },
{ title: "Address" },
{ title: "City" },
{ title: "State" },
{ title: "Zip Code" },
{ title: "Phone" },
{ title: "Shirt Size" },
{ title: "Company Name" },
{ title: "Member Since" }
]
});
});
});
$(文档).ready(函数(){
var userData=[];
$.ajax({
键入:“获取”,
url:“/api/User”,
contentType:“应用程序/json”,
}).完成(功能(d){
var userArray=[];
//控制台日志(d);
对于(i=0;i
我的HTML类。其余部分将动态加载。此部分将显示在正文中
<script src="js/admin-home.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<table id="example" class= "display" cellspacing="0">
</table>
使用
列属性
$('#example').dataTable( {
"columns": [
{ "title": "My column title" },
..
...
....
]
} );
您正在将JSON对象数组传递到DataTable?因此,您为每个列指定了一个标题,但在JSON对象中没有任何内容可供其引用。您需要向每个columns对象添加
数据
,如下所示:{“title”:“User ID”,“data”:“ID”},…
我应该镜像