我正在尝试使用 Nodejs 和 MSSQL 数据库后端为我的 jquery 数据表实现服务器端渲染。
这是我的客户端代码:
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
});
在我的 Nodejs 后端服务器上:
let result = await rows.query(My Query)
myJSON = {
"draw": 1,
"recordsTotal": 25,
"recordsFiltered": 25,
"sEcho":25,
"data": result.recordset
}
我的目标是每页有 25 个项目。但这个方法是重新调整整个3000行数据,没有分页。谁能帮助我在数据表中使用服务器端渲染时如何设置分页?
请检查 pankaj kumar 的答案 jQuery Datatable with NodeJS & MySql
您可以导入这个简短的库代码,以通过 mysql 和sequelize 使用节点中数据表的服务器端功能