【发布时间】:2015-12-08 12:05:33
【问题描述】:
我一直在尝试在 jQuery DataTables 组件中获取我的 JSON 数据。
首先我编写了一个 JavaScript 和一个视图,如下所示:
$.fn.dataTable.Editor({
ajax: "http://localhost/example22/index.php?r=site/display",
table: "#example",
fields: [{
label: "Name:",
name: "name"
}, {
label: "Designation:",
name: "designation"
}, {
label: "Address:",
name: "address"
}, {
label: "Salary:",
name: "salary"
}]
});
$('#example').DataTable({
lengthChange: false,
ajax: "http://localhost/example22/index.php?r=site/display",
columns: [{
allk: "name"
}, {
allk: "designation"
}, {
allk: "address"
}, {
allk: "salary"
}],
select: true
});
和类似的视图
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Designation</th>
<th>Address</th>
<th>Salary</th>
</tr>
</thead>
</table>
并且提供的url分别包含以下JSON数据
{
"allk": [
{
"name": "raju",
"designation": "developer",
"address": "he is from viswasapuram",
"salary": "30000"
},
{
"name": "bob",
"designation": "designer",
"address": "no idea",
"salary": "100000"
},
{
"name": "bob",
"designation": "designer",
"address": "no idea",
"salary": "100000"
},
{
"name": "suresh",
"designation": "designer",
"address": "fffswss",
"salary": "1212"
},
{
"name": "john",
"designation": "designer",
"address": "california",
"salary": "3000000"
},
{
"name": "suresh",
"designation": "tester",
"address": "he is from cheeran maanagar",
"salary": "20000"
}
]
}
有人可以帮助我了解如何在此应用程序中使用 DataTables 吗?
【问题讨论】:
标签: json yii datatables html-table