以下是测试我的问题的示例代码。一个本地数组mydata,在最后一列添加一个复选框添加到网格中。您可以通过简单的复制和粘贴立即运行它来查看我的问题。
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.16.custom.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/grid.locale-en.js" ></script>
<script type="text/javascript" src="js/jquery.jqGrid.min.js" ></script>
</head>
<body>
<table id="list4"></table>
<script type="text/javascript">
jQuery("#list4").jqGrid({
datatype: "local",
height: 250,
colNames:['Inv No', 'Client','Notes','Checked?' ],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'name',index:'name', width:100},
{name:'note',index:'note', width:150, sortable:false},
{name:'ind_checked',index:'ind_checked', width:100, sortable:false, align:'center', editable:true,
edittype:'checkbox', editoptions: { value:"Y:N" }, formatter:'checkbox'}
],
caption: "Testing Check Option" }
);
var mydata = [
{id:"1",name:"test1",note:"note1",ind_checked:"N"},
{id:"2",name:"test2",note:"note2",ind_checked:"N"},
{id:"3",name:"test3",note:"note3",ind_checked:"N"},
{id:"4",name:"test4",note:"note4",ind_checked:"N"},
{id:"5",name:"test5",note:"note5",ind_checked:"N"},
{id:"6",name:"test6",note:"note6",ind_checked:"N"},
{id:"7",name:"test7",note:"note7",ind_checked:"N"},
{id:"8",name:"test8",note:"note8",ind_checked:"N"},
{id:"9",name:"test9",note:"note9",ind_checked:"N"} ]
;
for(var i=0;i<=mydata.length;i++) {
jQuery("#list4").jqGrid('addRowData',i+1,mydata[i]);
var data = jQuery("#list4").jqGrid('getRowData',mydata[i].id);
alert('Row ID:'+data.id+'; My data:'+mydata[i].ind_checked+'; Data stored in Grid:'+data.ind_checked);
}
</script>
</body>
</html>
问题是
我最初在mydata中将所有字段'ind_checked'设置为'N'; 在我将mydata添加到网格后,我试图从网格中取回内容,发现它们都是'Y'并且存储不正确。
我不知道为什么,也不知道。有人可以告诉我我失踪了吗?谢谢。
P.S。我的jqGrid版本是4.3.1
答案 0 :(得分:1)
可能是你可以尝试这个
loadComplete: function (data) {
var rowCount = grid.getGridParam("reccount");
if ( rowCount > 0 ) {
for (var i = 0; i < data.rows.length; i++) {
if (data.rows[i].cell[4] == 'Y') { // 4 cell ind_checked//
$("tr#"+(data.rows[i].id)+".jqgrow > td > input.cbox:checked", grid[0]);
}
}
}
}
答案 1 :(得分:0)
以下是验证是否选中此复选框的替代解决方案。
function customFormatter(cellvalue, options, rowObject) {
var checkBoxValue = "N" ;
var cell = jQuery('#' + options.rowId + '_' + 'ind_checked');
var val = cell.prop("checked");
if(val == true) {
checkBoxValue = "Y";
}
return checkBoxValue;
}