Showing posts with label data tables server side implementation with nodejs. Show all posts
Showing posts with label data tables server side implementation with nodejs. Show all posts
Datatables Server Side Implementation with Nodejs and MongoDB
Surya
How to implement server side Datatables processing using Node-js and MongoDB (ExpressJs)
Something you should kept in mind is that -
1- Add Datatables CDN or offline link.
2- Try to implement client side Datatables first.(This is server side Implementation and to be used if your have more than 1000 record.)
• Now this is working Code.....
• this code to be used on client side (HTML) page
$('#example').dataTable({
processing: true,2- Try to implement client side Datatables first.(This is server side Implementation and to be used if your have more than 1000 record.)
• Now this is working Code.....
• this code to be used on client side (HTML) page
$('#example').dataTable({
destroy:true,
autoWidth:false,
sAjaxDataProp: 'data',
ajax:{
url: "/getData",
type: 'POST',
data: {"id":id,"product":prdMain},
dataSrc: ""
},
columns: [
{ data : "job_name" },
{ data : "product" },
{ data : "test_plan" }
] ,"fnRowCallback":function( nRow, aData, iDisplayIndex, iDisplayIndexFull ){
var dat1 = '<div >'+aData['job_name']+'</div>';
var dat2 = '<div >'+aData['product']+'</div>';
var dat3 = '<div >'+aData['test_plan']+'</div>';
$('td:eq(0)', nRow).html(dat1);
$('td:eq(1)', nRow).html(dat2);
$('td:eq(2)', nRow).html(dat3);
}
});
• Nodejs Controller code
router.post('/getData', function(req, res){
obj.getData(function (err,data) {
if (err) throw err;
else {
res.send(data); //send as it is to client page//
};
})
});
Models Code
• Fetching the data from MongoDB.
module.exports.getData= function (callback) {
Data.find({},callback); //.Find is Used to get all data.
}
Subscribe to:
Posts
(
Atom
)
