我使用Datatables 2.0。如何设置显示行数的限制?
我有1000行数据,全部显示在一页上。 在Datatables 1.9中,可以使用“iDisplaylenght”进行设置。 但在Datatable 2.0中,我尝试像文档中所述设置'lenght:10': http://next.datatables.net/manual/server-side 但它不起作用。
编辑:
在上面的链接中,您可以看到我的问题。
无论我从复选框中选择哪个数字都没有关系。
我已经发现,使用@Julian提供的链接,如果我不使用ajax调用,它可以正常工作。但是,如果我从服务器端获取数据,所有数据都会显示出来。请参见链接。所以这必须是服务器端的问题?!
这是我的服务器代码。
我有1000行数据,全部显示在一页上。 在Datatables 1.9中,可以使用“iDisplaylenght”进行设置。 但在Datatable 2.0中,我尝试像文档中所述设置'lenght:10': http://next.datatables.net/manual/server-side 但它不起作用。
编辑:
![enter image description here](https://istack.dev59.com/UcIlM.webp)
![enter image description here](https://istack.dev59.com/W8Rsi.webp)
![enter image description here](https://istack.dev59.com/rhCAA.webp)
![enter image description here](https://istack.dev59.com/ED6pK.webp)
我已经发现,使用@Julian提供的链接,如果我不使用ajax调用,它可以正常工作。但是,如果我从服务器端获取数据,所有数据都会显示出来。请参见链接。所以这必须是服务器端的问题?!
@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sql = "SELECT UID,LastName,FirstName FROM employe LIMIT 1000";
int rows=0;
int count = 0;
JSONArray arrayback = new JSONArray();
JSONObject object = new JSONObject();
PrintWriter out = response.getWriter();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/check","****","****");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData meta = rs.getMetaData();
rows= meta.getColumnCount();
while(rs.next())
{
JSONArray array = new JSONArray();
array.add(rs.getString("UID"));
array.add(rs.getString("LastName"));
array.add(rs.getString("FirstName"));
count++;
arrayback.add(array);
}
object.put("aaData", arrayback);
object.put("sEcho",1);
object.put("iTotalRecords", count);
object.put("iTotalDisplayRecords", count);
out.print(object);
con.close();
}catch(exception e)
{
e.printStackTrace();
}
}
这是我的服务器代码。