I am trying to implement server side rendering for my jquery datatables with Nodejs and MSSQL database backend.
This is my client side code:
let tblAssignedJobs = $('#tblAssignedJobs').DataTable({
"oLanguage": {
"sEmptyTable": "There are no jobs assigned to you at this moment"
},
autoWidth : false
,serverSide:true
,responsive : true
,deferRender : true
,processing : true
,paging : true
,pageLength : 25
,searching : true
,info : true
,ordering : true
,dom : "<ipf>"
,bPaginate : false
,sDom :"fptip",
"aoColumns": [{
"mData":"studentNumber"
},{
"mData": "studentType"
}
,
{
"mData":"Description"
}
,
{
"mData":"LocationNumber"
}
,
{
"mData":"Address"
},
{ "mData":"StudentNumber",
"mRender": function(data, type, full) {
return `<a href = '/editStudent?studentNumber=${data}'><button class='btn btn-primary'>Edit Job</button></a>`
}
}
],
ajax: {
url: "students",
type: "POST"
},
responsive: true
});
On my Nodejs backend server:
let result = await rows.query(My Query)
myJSON = {
"draw": 1,
"recordsTotal": 25,
"recordsFiltered": 25,
"sEcho":25,
"data": result.recordset
}
My goal is to have 25 items per page. But this method is retruning the entire 3000 rows of data without pagination. Can anyone help me on how to setup pagination when using server side rendering in datatables?
"data"section of your response with the correct 25 records, based on the page number requested, any filtering requested, column sorting, etc (see here). Does that server-side logic exist?req.paramsbut when I console log it, it is just an empty object{}.type: 'POST'(same as you) in my ajax call, I can see the request details in my Firefox browser: Network tab > the POST record > Params. If you cannot see that, then that may be a new question you can research.