在jqGrid中設置multiselect: true能夠實現全選的操做,但怎麼設置被選中的checkbox裏面的值呢,作法以下:
jQuery("#listTable").jqGrid({
url: 'queryList.do',
datatype: 'json',
colNames: ['','編號','姓名'],
colModel: [
{
name: 'MY_ID',
index: 'MY_ID',
sortable: false,
width: '0%',
hidden:true
},
{
name: 'MY_NO',
index:'MY_NO',
sortable: false,
align:'center',
width:'10%'
},
{
name: 'NAME',
index:'NAME',
sortable: false,
align:'center',
width:'10%'
}
],
page: 1,
rowNum: 10,
rowList: [10, 20, 30],
pager: '#listPage',
multiselect: true,
sortname: 'MY_NO',
viewrecords: true,
sortorder: "desc",
jsonReader: {
repeatitems: false
},
width: "100%",
height: '100%',
gridComplete: function() {
var rowIds = jQuery("#listTable").jqGrid('getDataIDs');
for(var k=0; k<rowIds.length; k++) {
var curRowData = jQuery("#listTable").jqGrid('getRowData', rowIds[k]);
var curChk = $("#"+rowIds[k]+"").find(":checkbox");
curChk.attr('name', 'checkboxname'); //給每個checkbox賦名字
curChk.attr('value', curRowData['MY_ID']); //給checkbox賦值
curChk.attr('title', curRowData['NAME'] ); //給checkbox賦予額外的屬性值json