我一直在处理数据表。一切都很好地工作,问题是-分页工作不完美,-搜索不工作-所有数据只显示在一个页面上
我使用下面的代码初始化datatable-
$(document).ready(function () {
$('#example').DataTable({
"processing" : true,
"serverSide" : true,
"pageLength" : 5,
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"ajax" : {
url: "/users",
type:"GET",
dataSrc : "data",
},
"columns":[
{"data": "id"},
{"data": "name"},
{"data": "tweet"}
]
});
});
和我的控制器服务(播放框架)
public Result ListAll(){
List<User> users = User.find.all();
System.out.println(toJson(users).toString());
DataTableObject dataTableObject = new DataTableObject();
dataTableObject.setData(users);
String json = toJson(dataTableObject).toString();
System.out.println("----> " + json );
return ok(toJson(dataTableObject));
}
和datatableobject类
public class DataTableObject {
int draw = 1;
int recordsTotal= 26;
int recordsFiltered =26;
List<User> data;
public int getRecordsTotal() {
return recordsTotal;
}
public void setDraw(int draw) {
this.draw = draw;
}
public int getDraw() {
return draw;
}
public void setRecordsTotal(int recordsTotal) {
this.recordsTotal = recordsTotal;
}
public int getRecordsFiltered() {
return recordsFiltered;
}
public void setRecordsFiltered(int recordsFiltered) {
this.recordsFiltered = recordsFiltered;
}
public List<User> getData() {
return data;
}
public void setData(List<User> data) {
this.data = data;
}
}
这是我的电脑截图http://localhost:9000/
1条答案
按热度按时间yyyllmsg1#
使用时
serverSide:true
datatables不处理搜索、筛选、分页或排序。在对表进行分页、排序或搜索时,必须根据datatables随get/post请求一起发送的参数来操作查询。