带有Node.js的jQuery DataTables [英] jQuery DataTables with Node.js
问题描述
所以我正在尝试使用datatables插件实现分页表,这是我第一次使用此插件.我按照插件文档中的说明进行操作,并尝试通过使用Ajax从服务器获取值,如插件文档中所述.
So i am trying to implement a pagination table with the datatables plugin, this is my first time using this plugin. I followed the documentation on the plugin and tried to get the values from the server through the use of Ajax, as per presented in the plugins documentation.
发出get请求后,我似乎会收到以下错误,但我不确定为什么?
I seem to be getting the following error once i make the get request and i am unsure of why?
错误:未捕获的类型错误:无法读取未定义的属性'length'
在客户端,我有以下代码
On client side i have the following code
viewReports = {
init: function(){
$('#paginatedData').DataTable({
"processing": true,
"serverSide": true,
"ajax": '/viewreports'
});
}
};
$(document).ready(viewReports.init);
在服务器端,我有以下内容
In my server side i have the following
router.get('/viewreports', function(res, req){
async.parallel({
viewReports: function(callback){
restCall('/rest/bugbounty/latest/message/searchReport', 'POST', parameters, function(data){
callback(null, data);
});
}
}, function(err, result){
if(!err){
res.send(result.viewReports);
res.render('viewreports');
}
});
});
返回的JSON:
{reportList:[{reportID:'EIBBP-448',eBayUserID:'',reportStatus:'New',摘要:'BugBounty由Raj创建的报告',lastUpdatedDate:'2015-06-15 01:05', createdDate:'2015-06-15 01:05',paypalLoginID:'raaj@paypal.com'}],searchStatus:'Success',eBayUserID:'',errorCode:'0',rowCount:'6',pageNumber: '1',paginationValue:'1',paypalLoginID:'raaj@paypal.com'}
{ reportList: [ { reportID: 'EIBBP-448', eBayUserID: ' ', reportStatus: 'New', summary: 'BugBounty Report created by Raj', lastUpdatedDate: '2015-06-15 01:05', createdDate: '2015-06-15 01:05', paypalLoginID: 'raaj@paypal.com' } ], searchStatus: 'Success', eBayUserID: '', errorCode: '0', rowCount: '6', pageNumber: '1', paginationValue: '1', paypalLoginID: 'raaj@paypal.com' }
很高兴知道是否有人从事过node.js服务器端数据表处理工作
It would be great to know if there is anyone who has worked with node.js server side processing for datatables
推荐答案
您需要定义 columns.data
-以下应该起作用:
You need to define dataSrc
and columns.data
- the following should work :
var table = $('#example').DataTable({
processing: true,
serverSide: true,
ajax: {
url: "/viewreports",
dataSrc: "reportList"
},
columns: [
{ data : "reportID" },
{ data : "eBayUserID" },
{ data : "reportStatus" },
{ data : "summary" },
{ data : "lastUpdatedDate" },
{ data : "createdDate" },
{ data : "paypalLoginID" }
]
});
在一个空表上:
<table id="example"></table>
-
dataSrc
以指定保存行项目的数组的名称(原因为"无法读取未定义的属性'length'") -
columns.data
将项目属性映射到列 dataSrc
to specify what the array holding row items is named (cause of "Cannot read property 'length' of undefined")columns.data
to map item properties to columns
这篇关于带有Node.js的jQuery DataTables的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!