Not able to set iTotalRecords and iTotalDisplayRecords in datatable
Not able to set iTotalRecords and iTotalDisplayRecords in datatable
Hi Sir,
I am using mvc architecture for my project . i was trying to implement datatable but was not able to set the iTotalRecords and iTotalDisplayRecords parameters in datatable
here is my code
$("#tableData").DataTable({
"bProcessing": true,
"bServerSide": true,
"bsort":true,
"orderMulti":true,
"sAjaxSource":"datalist",
"sAjaxDataProp": function ( json ) {
var msgObj = JSON.parse(json);
console.log(msgObj)
return msgObj.aaData ;
} ,
"aoColumns": [
{ "data": "scheduleId" },
{ "data": "startTime" },
{ "data": "endTime" },
{ "data": "selectFlag" }
]
})
json data
{"iTotalRecords":7,"iTotalDisplayRecords":7,"aaData":[{"scheduleId":1,"startTime":"02:00","endTime":"04:00","selectFlag":false},{"scheduleId":2,"startTime":"02:00","endTime":"04:00","selectFlag":false},{"scheduleId":3,"startTime":"02:00","endTime":"04:00","selectFlag":false},{"scheduleId":4,"startTime":"02:00","endTime":"04:00","selectFlag":false},{"scheduleId":5,"startTime":"02:00","endTime":"04:00","selectFlag":false},{"scheduleId":6,"startTime":"02:00","endTime":"04:00","selectFlag":false},{"scheduleId":7,"startTime":"03:00","endTime":"04:00","selectFlag":false}]}
My controller class
public DatatableObj datatableObj ; //get set
public List<ScheduleObj> scheduleList; //get set
String jsonString ; //get set
//DatatableObj is a pojo class which consist of variables iTotalRecords , iTotalDisplayRecords, aaData
public String datalist(){
datatableObj = new DatatableObj();
//scheduleList consist of list of data's from the table
datatableObj.setiTotalDisplayRecords(scheduleList.size());
datatableObj.setiTotalRecords(scheduleList.size());
datatableObj.setAaData(scheduleList);
jsonString = new Gson().toJson(datatableObj);
return SUCCESS;
}