我正在尝试修改我的jqgrid表添加虚拟滚动功能。我找不到问题的原因:我滚动到底部,新行没有出来。 这是我的js代码:
$(document).ready(function()
{
var page;
$("#visual").click(function()
{
$("#list").jqGrid(
{
url:'PrendiTutto',
datatype: "json",
height: 400,
width:600,
colNames:['id','model','cc','nation','prod'],
colModel:[
{name:'id', index:'id', jsonmap:"id", width:25},
{name:'model', index:'model', jsonmap:"model", width:50},
{name:'cc', index:'cc', jsonmap:"cc", width:25},
{name:'nation', index:'nation', jsonmap:"nation", width:50},
{name:'prod', index:'prod', jsonmap:"prod", width:50}
],
rowNum: 40,
rowTotal: 2000,
rowList: [20,30,50],
scrollrows: false,
hoverrows: false,
scroll: 10,
pager: false,
loadonce: true,
mtype: 'GET',
rownumbers: true,
rownumWidth: 40,
gridview: true,
pager: '#pager',
sortname: 'id',
viewrecords: true,
sortorder: "asc",
caption: "Elenco delle Moto",
jsonReader: {root: 'rows',page: 'page',total: 'total',records: 'records',repeatitems: false,id: 'id'},
});
$("#list").jqGrid('navGrid','#pager',{del:false,add:false,edit:false},{},{},{},{multipleSearch:true});
$("#visual").fadeOut();
$("#next").fadeIn();
$("#add").fadeIn();
$("#remove").fadeIn();
page = $("#list").getGridParam("page");
});
$("#next").click(function()
{
page = $("#list").getGridParam("page");
total = $("#list").getGridParam("lastpage");
if(total != page)
{
page ++;
$("#list").setGridParam({page:page}).trigger("reloadGrid");
$("#prev").fadeIn();
}
if((total) <= page)
$("#next").fadeOut();
});
$("#add").click(function()
{
row = $("#list").getGridParam("rowNum");
if(8 > row)
{
row++;
$("#list").setGridParam({rowNum:row}).trigger("reloadGrid");
}
});
$("#remove").click(function()
{
row = $("#list").getGridParam("rowNum");
if(row > 1)
{
row--;
$("#list").setGridParam({rowNum:row}).trigger("reloadGrid");
}
});
$("#prev").click(function()
{
page = $("#list").getGridParam("page");
if(page > 1)
{
page --;
$("#list").setGridParam({page:page}).trigger("reloadGrid");
$("#next").fadeIn();
}
if(page <= 1)
$("#prev").fadeOut();
});
});
以及从db:
读取数据的servletpublic class PrendiTutto extends HttpServlet
{
private static final long serialVersionUID = 1L;
public PrendiTutto()
{
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/json");
MotoBeanManager moma = new MotoBeanManager();
Collection<MotoBean> m = moma.loadMotos();
PrintWriter out = response.getWriter();
int page = Integer.parseInt(request.getParameter("page"));
int row = Integer.parseInt(request.getParameter("rows"));
int j = 0, k = 0;
int pagine = m.size()/row;
if((m.size()%row) != 0)
pagine++;
String json = "{\"total\": \"" + pagine + "\",\"page\":\"" + page + "\",\"records\" :\"" + m.size() + "\", \"rows\":";
json += "[";
for(Iterator<MotoBean> i = m.iterator(); i.hasNext(); j++)
{
MotoBean moto = i.next();
if((j < page*row)&&(j >= (page - 1)*row))
{
k++;
json += "{";
json += "\"id\": \"" + moto.getId() + "\",";
json += "\"model\": \"" + moto.getModel() + "\",";
json += "\"cc\": \"" + moto.getCc() + "\",";
json += "\"nation\": \"" + moto.getNation() + "\",";
json += "\"prod\": \"" + moto.getProd() + "\"";
json += "}";
if((k != row)&&(i.hasNext()))
json += ",";
}
}
json += "]}";
out.print(json);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGet(request,response);
}
}
任何人都可以帮助我吗?
答案 0 :(得分:0)
你有
loadonce: true
应该是:
loadonce: false