我无法在Jgrid中退出所选行的ID ....
我有一个jgrid
jQuery("#grid").jqGrid({
....................
});
我在同一个jsp页面中有一个按钮
<input type ="button" name="button" id="button" value="OK">
点击按钮后,我应该可以从上面的网格中检索所有选定的行。 这是我的功能,
jQuery("#button").click(function ()
var select = jQuery("#grid").jqGrid("getGridParam", "selarrrow");
for (var i = 0; i < select.length; i++) //iterate through array of selected rows
{
alert("inside the loop");
var id = jQuery("#grid").jqGrid('getRowData', select[i]);
var selectedID = id.Emp_ID;
});
我无法解除ids。 请帮忙
请在此处找到完整的代码
function load()
{
jQuery("#grid").jqGrid({
url:'Emp?action=getData',
datatype: "xml",
height: 250,
width:900,
colNames:
['srNo','Emp_ID','NAME','ADDRESS'],
colModel:[
{name:'srNo',index:'srNo', width:35,sortable:true},
{name:'Emp_ID',index:'Emp_ID', width:20,sortable:true,editable:true},
{name:'NAME',index:'NAME', width:35,sortable:false,editable:true},
{name:'ADDRESS',index:'ADDRESS', width:100,sortable:false,editable:true},
],
paging: true,
rowNum:10,
rowList:[10,20,30],
pager: $("#page"),
sortname: 'srNo',
loadonce:true,
multiselect:true,
gridComplete: function() {
var actualrows = $("#grid").getGridParam("reccount");
document.getElementById("rows").value = actualrows;
}
}).navGrid
('#page',{edit:true,add:true,del:true,view:true,search: true},
{closeOnEscape:true, recreateForm: true,width:500,editurl: '', closeOnSubmit: true},
{closeOnEscape:true, recreateForm: true,width:500,url: '', closeOnSubmit: true},
{closeOnEscape:true, recreateForm: true,width:500,url: '', closeOnSubmit: true},
{multipleSearch:true,overlay:false}
);
}
jQuery("#button").click(function ()
{
var select = jQuery("#grid").jqGrid("getGridParam", "selarrrow");
for (var i = 0; i < select.length; i++) //iterate through array of selected rows
{
alert("inside the loop");
var id = jQuery("#grid").jqGrid('getRowData', select[i]);
var selectedID = id.Emp_ID;
}
});
</script>
</head>
<body onload="load();">
<table id="grid" border="1"></table>
<div id="page"></div>
<input type ="hidden" name = "hidden" id ="hidden">
<input type="hidden" id = "rows" name="actualrows" />
<table align ="center">
<tr>
<td>Date</td>
<td><input type ="text" name="regdate" id ="regdate"></td></tr>
<tr><td></td><td><input type ="button" class ="button" name="button" id="button" value="OK"></td></tr>
</table>
</body>
</html>
以下是我在网格中包含的测试数据
1 Emp1 Andrew addr
2 Emp2 Cyrus addr
3 Emp3 Tom addr
这是填充网格的Servlet
if (request.getParameter("action").equals("getData"))
{
try
{
String query="Select * from Employee";
/* Connection code goes here*/
pstmt = con.prepareStatement(query);
/* pagination code goes here*/
out.print("<?xml version='1.0' encoding='utf-8'?>\n");
out.print("<rows>");
out.print("<page>" + page + "</page>");
out.print("<total>" + totalPages + "</total>");
out.print("<records>" + count + "</records>");
while(rs.next())
{
out.print("<row id='" + srNo + "'>");
out.print("<cell>" + srNo + "</cell>");
out.print("<cell>" +rs.getString(1) + "</cell>");
out.print("<cell>"+rs.getString(2) +"</cell>");
out.print("<cell>"+rs.getString(3) +"</cell>");
out.print("</row>");
srNo++;
}
out.print("</rows>");
}
catch(Exception e)
{
}
}
请在下面找到XML响应...
<body onload="fillGrid();">
<div class="ui-jqgrid ui-widget ui-widget-content ui-corner-all" id="gbox_grid" style="width: 900px;"><div class="ui-widget-overlay jqgrid-overlay" id="lui_grid"></div><div class="loading ui-state-default ui-state-active" id="load_grid" style="display: none;">Loading...</div><div class="ui-jqgrid-view" id="gview_grid" style="width: 900px;"><div class="ui-jqgrid-titlebar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix" style="display: none;"><a role="link" href="javascript:void(0)" class="ui-jqgrid-titlebar-close HeaderButton"><span class="ui-icon ui-icon-circle-triangle-n"></span></a><span class="ui-jqgrid-title"></span></div><div style="width: 900px;" class="ui-state-default ui-jqgrid-hdiv"><div class="ui-jqgrid-hbox"><table class="ui-jqgrid-htable" style="width:882px" role="grid" aria-labelledby="gbox_grid" cellspacing="0" cellpadding="0" border="0"><thead><tr class="ui-jqgrid-labels" role="rowheader"><th role="columnheader" class="ui-state-default ui-th-column" style="width: 25px;"><div id="jqgh_cb"><input id="cb_jqg" class="cbox" type="checkbox"><span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"></span></span></div></th><th role="columnheader" class="ui-state-default ui-th-column" style="width: 157px;"><span class="ui-jqgrid-resize"> </span><div id="jqgh_srNo" class="ui-jqgrid-sortable">srNo<span class="s-ico" style=""><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-icon ui-icon-triangle-1-n"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"></span></span></div></th><th role="columnheader" class="ui-state-default ui-th-column" style="width: 90px;"><span class="ui-jqgrid-resize"> </span><div id="jqgh_Emp_ID" class="ui-jqgrid-sortable">Emp_ID<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"></span></span></div></th><th role="columnheader" class="ui-state-default ui-th-column" style="width: 157px;"><span class="ui-jqgrid-resize"> </span><div id="jqgh_NAME" class="ui-jqgrid-sortable">NAME<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"></span></span></div></th><th role="columnheader" class="ui-state-default ui-th-column" style="width: 453px;"><span class="ui-jqgrid-resize"> </span><div id="jqgh_ADDRESS" class="ui-jqgrid-sortable">ADDRESS<span class="s-ico" style="display:none"><span sort="asc" class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n"></span><span sort="desc" class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s"></span></span></div></th></tr></thead></table></div></div><div class="ui-jqgrid-bdiv" style="height: 250px; width: 900px;"><table id="grid" border="0" cellspacing="0" cellpadding="0" role="grid" aria-multiselectable="true" aria-labelledby="gbox_grid" class="ui-jqgrid-btable" style="width: 882px;"><tbody><tr id="1" role="row" class="ui-widget-content jqgrow ui-state-highlight" aria-selected="true"><td role="gridcell" style="text-align:center;width: 25px;"><input type="checkbox" id="jqg_1" class="cbox" name="jqg_1" checked="checked"></td><td role="gridcell" style="width: 157px;" title="1">1</td><td role="gridcell" style="width: 90px;" title="Emp1">Emp1</td><td role="gridcell" style="width: 157px;" title="Andrew">Andrew</td><td role="gridcell" style="width: 453px;" title="addr">addr</td></tr><tr id="2" role="row" class="ui-widget-content jqgrow ui-state-highlight" aria-selected="true"><td role="gridcell" style="text-align:center;"><input type="checkbox" id="jqg_2" class="cbox" name="jqg_2" checked="checked"></td><td role="gridcell" style="" title="2">2</td><td role="gridcell" style="" title="Emp2">Emp2</td><td role="gridcell" style="" title="Cyrus">Cyrus</td><td role="gridcell" style="" title="addr">addr</td></tr><tr id="3" role="row" class="ui-widget-content jqgrow"><td role="gridcell" style="text-align:center;"><input type="checkbox" id="jqg_3" class="cbox" name="jqg_3"></td><td role="gridcell" style="" title="3">3</td><td role="gridcell" style="" title="Emp3">Emp3</td><td role="gridcell" style="" title="Tom">Tom</td><td role="gridcell" style="" title="addr">addr</td></tr></tbody></table></div></div><div class="ui-jqgrid-resize-mark" id="rs_mgrid"> </div><div id="page" style="width: 900px;" class="ui-state-default ui-jqgrid-pager corner-bottom"><div id="pg_page" class="ui-pager-control" role="group"><table cellspacing="0" cellpadding="0" border="0" class="ui-pg-table" style="width:100%;table-layout:fixed;" role="row"><tbody><tr><td id="page_left" align="left"><table cellspacing="0" cellpadding="0" border="0" class="ui-pg-table navtable" style="float:left;table-layout:auto;"><tbody><tr><td class="ui-pg-button ui-corner-all" title="Add new row" id="add_grid"><div class="ui-pg-div"><span class="ui-icon ui-icon-plus"></span></div></td><td class="ui-pg-button ui-corner-all" title="Edit selected row" id="edit_grid"><div class="ui-pg-div"><span class="ui-icon ui-icon-pencil"></span></div></td><td class="ui-pg-button ui-corner-all" title="View selected row" id="view_grid"><div class="ui-pg-div"><span class="ui-icon ui-icon-document"></span></div></td><td class="ui-pg-button ui-corner-all" title="Delete selected row" id="del_grid"><div class="ui-pg-div"><span class="ui-icon ui-icon-trash"></span></div></td><td class="ui-pg-button ui-state-disabled" style="width:4px;"><span class="ui-separator"></span></td><td class="ui-pg-button ui-corner-all" title="Find records" id="search_grid"><div class="ui-pg-div"><span class="ui-icon ui-icon-search"></span></div></td><td class="ui-pg-button ui-corner-all" title="Reload Grid" id="refresh_grid"><div class="ui-pg-div"><span class="ui-icon ui-icon-refresh"></span></div></td></tr></tbody></table></td><td id="page_center" align="center" style="white-space: nowrap; width: 278px;"><table cellspacing="0" cellpadding="0" border="0" style="table-layout:auto;" class="ui-pg-table"><tbody><tr><td id="first" class="ui-pg-button ui-corner-all ui-state-disabled"><span class="ui-icon ui-icon-seek-first"></span></td><td id="prev" class="ui-pg-button ui-corner-all ui-state-disabled"><span class="ui-icon ui-icon-seek-prev"></span></td><td class="ui-pg-button ui-state-disabled" style="width:4px;"><span class="ui-separator"></span></td><td>Page <input class="ui-pg-input" type="text" size="2" maxlength="7" value="0" role="textbox"> of <span id="sp_1">1</span></td><td class="ui-pg-button ui-state-disabled" style="width:4px;"><span class="ui-separator"></span></td><td id="next" class="ui-pg-button ui-corner-all ui-state-disabled" style="cursor: default;"><span class="ui-icon ui-icon-seek-next"></span></td><td id="last" class="ui-pg-button ui-corner-all ui-state-disabled"><span class="ui-icon ui-icon-seek-end"></span></td><td><select class="ui-pg-selbox" role="listbox"><option role="option" value="10" selected="">10</option><option role="option" value="20">20</option><option role="option" value="30">30</option></select></td></tr></tbody></table></td><td id="page_right" align="right"></td></tr></tbody></table></div></div></div>
<input type="hidden" name="hidden" id="hidden">
<input type="hidden" id="rows" name="actualrows" value="3">
<table align="center">
<tbody><tr>
<td>Date</td>
<td><input type="text" name="regdate" id="regdate"></td></tr>
<tr><td></td><td><input type="button" class="button" name="button" id="button" value="OK"></td></tr>
</tbody></table>
警告请选择行
答案 0 :(得分:0)
我想你只是没有在用于jqGrid的XML输入中填充id
。
如果Emp_ID
列的包含对于每一行都是唯一的,那么您只需在列定义中包含key: true
属性(在colModel
中)。在jqGrid将使用Emp_ID
值作为id
行(作为rowid)的情况下,jQuery("#grid").jqGrid("getGridParam", "selarrrow");
返回的数组将为您提供所需的全部内容。