1
我試圖使用jQuery DataTables。在我使用引導表之前。 在服務器上,我使用彈簧啓動,帶分頁的彈簧數據。使用返回的服務器參數來顯示數據
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>memberId</th>
<th>name</th>
<th>phone1</th>
<th>phone2</th>
<th>email</th>
</tr>
</thead>
</table>
$('#example').DataTable({
"processing": "true",
"serverSide": "true",
"ajax": {
"url": "/rest/members",
"data": function (d) {
return {
search: d.search.value,
page: d.start,
size: d.length
}
},
dataFilter: function (data) {
var json = jQuery.parseJSON(data);
json.recordsTotal = json.totalElements;
json.data = json.content;
return JSON.stringify(json); // return JSON string
}
}
});
與服務器返回的值,我試圖顯示的數據。事實上,沒有任何顯示
{
"content":[
{
"memberId":1,
"name":"bob",
"phone1": "450",
"phone2": "1",
"email": "test"
},
{
"memberId":2,
"name":"robert"
"phone1": "2323",
"phone2": "2",
"email": "test"
}
],
"last":true,
"totalElements":27,
"totalPages":1,
"sort":null,
"numberOfElements":27,
"first":true,
"size":100,
"number":0
}
編輯
數據表警告:表ID =例如 - 請求的未知參數「0」 0行,列0。有關此錯誤的詳細信息,請參閱http://datatables.net/tn/4
看到編輯,我做了修飾 –
@roberttrudel,現在缺少一個逗號:)見更新,已經做了一個小提琴 - 真的沒什麼需要補充的。 – davidkonrad