I have been working with data-table . everything is working quite fine, the issues is that - pagination not working perfectly, - searching not working - all data showing only in one page
I used the below code for the initialization of the 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"}
]
});
});
and my controller servie (play framework)
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));
}
and DataTableObject class
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;
}
}
and this is a screenshot of my http://localhost:9000/
When using serverSide:true
Datatables does not handle searching, filtering, paging or ordering. You have to manipulate your query based on the sent parameters datatables is sending with the Get/Post request when you page, sort or search on your table.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.