我一直在使用data-table。一切都很好,问题是 -分页效果不佳, -搜索不起作用 -所有数据仅显示在一页中
我使用以下代码初始化数据表-
$(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;
}
}
的屏幕截图