Sample Code of Data encapsulation in the jquery datatable background, jquerydatatable
1. Data Conversion
public class DataTableReturnObject { private int iTotalRecords; private int iTotalDisplayRecords; private String sEcho; private String[][] aaData; public DataTableReturnObject(int totalRecords, int totalDisplayRecords, String echo, String[][] d) { this.setiTotalRecords(totalRecords); this.setiTotalDisplayRecords(totalDisplayRecords); this.setsEcho(echo); this.setAaData(d); } public void setiTotalRecords(int iTotalRecords) { this.iTotalRecords = iTotalRecords; } public int getiTotalRecords() { return iTotalRecords; } public void setiTotalDisplayRecords(int iTotalDisplayRecords) { this.iTotalDisplayRecords = iTotalDisplayRecords; } public int getiTotalDisplayRecords() { return iTotalDisplayRecords; } public void setsEcho(String sEcho) { this.sEcho = sEcho; } public String getsEcho() { return sEcho; } public void setAaData(String[][] aaData) { this.aaData = aaData; } public String[][] getAaData() { return aaData; } }
2. Help class
public class BaseController { protected JSONResponse successed(Object obj) { JSONResponse ret = new JSONResponse(); ret.setSuccessed(true); ret.setReturnObject(obj); return ret; } }
3. Implementation class
Public JSONResponse searchList (HttpServletRequest request, HttpServletResponse response, String sEcho) throws Exception {// convertToMap is defined in the parent class, adding all elements in the parameter array to a HashMap Map <Object, object> objQueryMap = new HashMap <Object, Object> (); String jsondata = request. getParameter ("aoData"); JSONArray jsonarray = JSONArray. fromObject (jsondata); String strDisplayStart = ""; String strDisplayLength = ""; String [] arrayColumen = new String [new JSONUser (). toArray (). length]; int strSortId = 0; String strSort = ""; for (int I = 0; I <jsonarray. size (); I ++) // select the parameter to be used from the transmitted parameter {JSONObject obj = (JSONObject) jsonarray. get (I); String strName = (String) obj. get ("name"); String strValue = obj. get ("value "). toString (); if (strName. equals ("sEcho") {sEcho = strValue;} if (strName. equals ("iDisplayStart") {strDisplayStart = strValue;} if (strName. equals ("iDisplayLength") {strDisplayLength = strValue;} if (strName. equals ("sColumns") {arrayColumen = obj. get ("value "). toString (). split (",");} if (strName. startsWith ("iSortCol _") {strSortId = Integer. parseInt (strValue); // Number of sorted columns} if (strName. startsWith ("sSortDir _") {strSort = strValue; // the direction of sorting "desc" or "asc ".}} map <Object, Object> params = new HashMap <Object, Object> (); try {params = managerService. getUserList (parameter);} catch (Exception e) {// TODO Auto-generated catch block e. printStackTrace ();} String count = (String) params. get ("COUNT"); // total String [] [] strData = (String [] []) params. get ("AO_DATA"); // return successed (new DataTableReturnObject (Integer. parseInt (count), Integer. parseInt (count), sEcho, strData ));}
4. Query Method
Public Map <Object, Object> getUserList (Map <Object, Object> queryParams) throws Exception {String iCount = Total number of records; // convert the query result to a two-dimensional array String [] [] data ={}; if (lstUser! = Null & lstUser. size ()> 0) {int record = lstUser. size (); data = new String [record] []; for (int I = 0; I <lstUser. size (); I ++) {User objUser = (User) lstUser. get (I); JSONUser jsonUser = new JSONUser (); BeanUtils. copyProperties (jsonUser, objUser); data [I] = jsonUser. toArray () ;}} queryParams. clear (); // map, reset the value to use queryParams. put ("AO_DATA", data); queryParams. put ("COUNT", iCount); return queryParams ;}
Note that the attributes of the stored array object must be the same as the number of columns displayed on the front-end page.
How can I read large volumes of data when I use jquery ajax to read background data?
I am working on java. java contains fastjson and other jar files. You should be. NET. You have uploaded the json data in the background to the front-end,
. Net I remember that I should be able to reference the DataContractJsonSerializer class, or you can go to the json.org website to find. NET-related JSON dll files, which may be easier to operate.
Front-End statement:
/**
* Parmas: Parameter
* Data: returned data
*/
$. GetJSON ('xxxx. aspx ', params, function (data ){
// Data can be directly operated as a dom object.
// If a json object of HashMap is returned, the value of data. name can be used in js.
// If the returned result is a json object of the List set, the js part can
For (var o in data ){
Alert (o. name );
}
})
Are you satisfied with the answer? If you are satisfied, please adopt it! Waiting to receive points!
The dataTable component of jquery needs to be used in the project. I have never touched jquery before and want to learn it. I am very grateful to anyone who wants to teach me. Or
I sent your email. Please check it!