javascript - jQuery DataTables with Node.js -
so trying implement pagination table datatables plugin, first time using plugin. followed documentation on plugin , tried values server through use of ajax, per presented in plugins documentation.
i seem getting following error once make request , unsure of why?
error: uncaught typeerror: cannot read property 'length' of undefined
on client side have following code
viewreports = { init: function(){ $('#paginateddata').datatable({ "processing": true, "serverside": true, "ajax": '/viewreports' }); } }; $(document).ready(viewreports.init);
in server side have 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'); } }); });
returned json:
{ reportlist: [ { reportid: 'eibbp-448', ebayuserid: ' ', reportstatus: 'new', summary: 'bugbounty report created 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' }
it great know if there has worked node.js server side processing datatables
you need define datasrc
, columns.data
- 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" } ] });
on empty table :
<table id="example"></table>
datasrc
specify array holding row items named (cause of "cannot read property 'length' of undefined")columns.data
map item properties columns
Comments
Post a Comment