0
我創建格蘭followng電網我如何獲得所有檢查行的列值?
這裏是它的代碼:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/le-frog/jquery-ui.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.13.6/css/ui.jqgrid.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<style>
</style>
</head>
<body>
<table id="list"></table>
<div>
<input type="button" id="btn" value="send" />
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script>
$.jgrid = $.jgrid || {};
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script src="https://rawgit.com/free-jqgrid/jqGrid/master/js/jquery.jqgrid.src.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var data =
[
{id:'1', name:'john dillon', city:'london', active:false},
{id:'2', name:'marcus maxi', city:'chicago', active:false},
{id:'3', name:'fedro james', city:'new york', active:false},
{id:'4', name:'alias hue', city:'georgia', active:false},
{id:'5', name:'greg finto', city:'st louis', active:false}
];
jQuery("#list").jqGrid({
data:data,
colNames: ['id','Name','City', 'active'],
colModel: [
{name: 'id', index: 'id', width: 220, sorttype:"int", hidden:false },
{name: 'name', index: 'name', width: 220 },
{name: 'city', index: 'city', width: 220 },
{name: 'active', index: 'active', width: 60, align: 'center',
edittype: 'checkbox',
editoptions: {value: 'Yes:No', defaultValue: 'Yes'},
formatoptions: { disabled: false},
formatter:function(cellvalue, options, rowObject)
{
if(rowObject.active===true)
{
return '<input type="checkbox" id="cbPassed-'+ rowObject.id +'" checked/>';
}
else
{
return '<input type="checkbox" id="cbPassed-'+rowObject.id+ '" />';
}
}
}
],
beforeSelectRow: function (rowid, e) {
var $self = $(this),
iCol = $.jgrid.getCellIndex($(e.target).closest("td")[0]),
cm = $self.jqGrid("getGridParam", "colModel"),
localData = $self.jqGrid("getLocalRow", rowid);
if (cm[iCol].name === "active") {
localData.active = $(e.target).is(":checked");
}
return true;
},
threeStateSort:true,
autoencode: true,
sortname: "id",
viewrecords: true,
sortorder: "asc",
shrinkToFit: false,
caption:'sampples'
//width:'400px'
});
$('#btn').click(function(){
var myGrid = $('#list');
var i,
selRowIds = myGrid.jqGrid("getGridParam", "selarrrow"),
n,
rowData;
console.log(JSON.stringify(selRowIds));
for (i = 0, n = selRowIds.length; i < n; i++)
{
rowData = myGrid.jqGrid("getLocalRow", selRowIds[i]);
console.log('selected row data:'+ JSON.stringify(rowData));
}
var grid = $('#list');
var ids = grid.jqGrid('getGridParam', 'selarrrow');
console.log(JSON.stringify(ids));
})
})
</script>
</body>
</html>
在格蘭那一刻,我按一下按鈕發送,它只是變得的的id
列值最後一次檢查行。但我如何獲得所有檢查行的所有name
列值?
感謝Oleg,複選框選擇問題已修復:) –
@ Dore.Ad:不客氣! – Oleg