以下是用於測試我的問題的示例代碼。本地數組,mydata,在最後一列添加複選框並添加到網格中。你可以簡單的複製和粘貼來立即運行它來查看我的問題。jqGrid - 複選框沒有得到正確的輸入值?
<!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
格式化爲複選框的列的接受值爲(false | 0 | no | off | undefined),反之亦然。所以ind_checked:「N」應該是ind_checked:「no」 editoptions僅用於編輯模式。 瞭解詳情:http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules – shakib 2012-01-09 09:01:40
shakib,非常感謝。 – early 2012-01-09 14:58:21