jqGrid代码:
<script>
jQuery("#task-grid").jqGrid({
url:call_url,
datatype: "json",
height: 'auto',
rowNum: 20,
rowList: [20,30],
colNames:['ID','RESOURCE','ROLE','SITE', 'ALLOC. TYPE', 'UNIT (%)'],
colModel:[
{name:'ID',key:true,index:'ID', width:50, align:'center',search:false,hidden: true},
{name:'RESOURCE',index:'RESOURCE', width:150, sorttype:"text",align:'center',search:true},
{name:'ROLE',index:'ROLE',width:120 ,align:'center',search:false},
{name:'SITE',index:'SITE', width:120, align:'center',search:false},
{name:'ALLOC. TYPE',index:'ALLOCATION_TYPE', align:'center',width:120,search:false },
{name:'UNIT',index:'UNIT',align:'center',search:false},
//{name:'HOURS',index:'HOURS', search:false, align:'center',sortable:false,editable:true}
],
pager: "#page",
shrinkToFit :true,
autowidth: true,
viewrecords: true,
sortname: 'RESOURCE',
sortorder: "asc",
multiselect: true,
cellEdit: true,
cellsubmit : 'clientArray',
caption: "Resource List"
}).navGrid('#page',{ edit:false,add:false,del:false,search:false,cloneToTop:true,refresh:false},
{
},{
//add options
},{
//msg: "do you really want delete this keyword? This delete affect on Eqms filter"
});
jQuery("#task-grid").jqGrid('filterToolbar', { autosearch: true });
var topPagerDiv = $('#grid_toppager')[0];
jQuery("#grid_toppager_center", topPagerDiv).remove();
</script>
jqGrid结构:
<table id="task-grid" class="ui-jqgrid-btable" cellspacing="0" cellpadding="0" border="0" tabindex="0" role="grid" aria-multiselectable="true">
<tr style="height:auto" role="row" class="jqgfirstrow"></tr>
<tr class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" id="13551" role="row">
<td aria-describedby="task-grid_cb" style="text-align:center;width: 25px;" role="gridcell"><input type="checkbox" name="jqg_task-grid_13551" class="cbox" id="jqg_task-grid_13551" role="checkbox"></td>
</tr>
<tr class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" id="12860" role="row">
<td aria-describedby="task-grid_cb" style="text-align:center;width: 25px;" role="gridcell"><input type="checkbox" name="jqg_task-grid_13551" class="cbox" id="jqg_task-grid_13551" role="checkbox"></td>
</tr>
<tr class="ui-widget-content jqgrow ui-row-ltr" tabindex="-1" id="12855" role="row">
<td aria-describedby="task-grid_cb" style="text-align:center;width: 25px;" role="gridcell"><input type="checkbox" name="jqg_task-grid_13551" class="cbox" id="jqg_task-grid_13551" role="checkbox"></td>
</tr>
</table>
获取ID的代码
var ids = jQuery("#task-grid").jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++)
{
var rowId = ids[i];
console.log(rowId);
}
控制台日志为我提供了13551, 12860 and 12855
ID <tr>
的ID {/ 1}。
如何将rowId's
与<tr>
ID匹配并保持选中复选框?
答案 0 :(得分:0)
我循环浏览rowArray
数组并为setSelection
中的每个rowid
调用rowArray
方法:
var i, count, $grid = $("#myTable");
for (i = 0, count = rowArray.length; i < count; i += 1) {
$grid.jqGrid('setSelection', rowArray[i], false);
}
此代码有效。