
HTML代码举例
jqGrid 实例
···代码省略···
···代码省略···
javascript代码举例
$(function(){
pageInit();
});
function pageInit(){
$("#list1").jqGrid(
{
url : ctx+'/XMLData',
datatype : "xml",
colNames : [ 'Inv No', 'Date', 'Client', 'Amount', 'Tax','Total', 'Notes' ],
colModel : [
{name : 'id',index : 'id',width : 75},
{name : 'invdate',index : 'invdate',width : 90},
{name : 'name',index : 'name',width : 100},
{name : 'amount',index : 'amount',width : 80,align : "right"},
{name : 'tax',index : 'tax',width : 80,align : "right"},
{name : 'total',index : 'total',width : 80,align : "right"},
{name : 'note',index : 'note',width : 150,sortable : false}
],
rowNum : 10,
autowidth : true,
rowList : [ 10, 20, 30 ],
pager : jQuery('#pager1'),
mtype : "post",
sortname : 'id',
viewrecords : true,
sortorder : "desc",
caption : "XML 实例"
}).navGrid('#pager1', {
edit : false,
add : false,
del : false
});
}
java servlet代码举例
public class XMLData extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public XMLData() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String xml = "" +
"" +
" 1" +
" 2" +
" 13" +
" 3820.00" +
" 462.00" +
" 4284.00" +
" " +
" 13" +
" 2007-10-06" +
" " +
" 1000.00" +
" 0.00" +
" 1000.00" +
" " +
" " +
" " +
" 12" +
" 2007-10-06" +
" " +
" 700.00" +
" 140.00" +
" 840.00" +
" " +
" " +
" " +
" 11" +
" 2007-10-06" +
" " +
" 600.00" +
" 120.00" +
" 720.00" +
" " +
" " +
" " +
" 10" +
" 2007-10-06" +
" " +
" 100.00" +
" 20.00" +
" 120.00" +
" " +
" " +
" " +
" 9" +
" 2007-10-06" +
" " +
" 200.00" +
" 40.00" +
" 240.00" +
" " +
" " +
" " +
" 8" +
" 2007-10-06" +
" " +
" 200.00" +
" 0.00" +
" 200.00" +
" " +
" " +
" " +
" 7" +
" 2007-10-05" +
" " +
" 120.00" +
" 12.00" +
" 134.00" +
" " +
" " +
" " +
" 6" +
" 2007-10-05" +
" " +
" 50.00" +
" 10.00" +
" 60.00" +
" " +
" " +
" " +
" 5" +
" 2007-10-05" +
" " +
" 100.00" +
" 0.00" +
" 100.00" +
" " +
" " +
" " +
" 4" +
" 2007-10-04" +
" " +
" 150.00" +
" 0.00" +
" 150.00" +
" " +
" " +
"";
response.getWriter().write(xml);
}
}