获取页面DataTable的排序和分页信息
private Map<String, Object> getOrderAndLimit(HttpServletRequest request){
Map<String, Object> param = new HashMap<String, Object>();
String start = request.getParameter("start");
String length = request.getParameter("length");
String order_colum_index = request.getParameter("order[0][column]");
String order_dir = request.getParameter("order[0][dir]");
String _order = "";
if(order_colum_index != null && order_dir != null){
_order = request.getParameter("columns[" + Integer.parseInt(order_colum_index) + "][data]") + " " + order_dir;
}
Map<String, Object> _limit = new HashMap<String, Object>();
_limit.put("_pstart", start);
_limit.put("_psize", length);
param.put("_order", _order);
param.put("_limit", _limit);
return param;
}
转化Ajax请求数据为DataTable可接受的Json字符串形式
private String GetResponseString(HttpServletRequest request, int recordsTotal, int recordsFiltered, List data){
Map<String, Object> map = new HashMap<String, Object>();
map.put("recordsTotal", recordsTotal);
map.put("recordsFiltered", recordsFiltered);
map.put("draw", Integer.parseInt(request.getParameter("draw")));
map.put("data", data);
try {
return JsonUtils.convertToString(map);
} catch (IOException e) {
e.printStackTrace();
return "";
}
}
private String GetResponseString(HttpServletRequest request, int recordsFiltered, List data){
return GetResponseString(request, recordsFiltered, recordsFiltered, data);
}