更好的解决方案:
<script type="text/javascript">
var boxUnformat = function (cellvalue, options, cell) { return '-1'; },
checkboxTemplate = {width:40, editable:true,
edittype: "checkbox", align: "center", unformat: boxUnformat,
formatter: "checkbox", editoptions: {"value": "Yes:No"},
formatoptions: { disabled: false }};
jQuery(document).ready(function($) {
$(document).on('change', 'input[type="checkbox"]', function(e){
var td = $(this).parent(), tr = $(td).parent(),
checked = $(this).attr('checked'),
ids = td.attr('aria-describedby').split('_'),
grid = $('#'+ids[0]),
iRow = grid.getInd(tr.attr('id'));
iCol = tr.find('td').index(td);
grid.editCell(iRow,iCol,true);
$('input[type="checkbox"]',td).attr('checked',!checked);
grid.saveCell(iRow,iCol);
});
});
</script>
在你colModel:
...
{name:'allowAccess', template: checkboxTemplate},
...
@Justin伟大的答案!谢谢,如果这是我的问题,我会给你打勾。 – Dan 2010-05-06 15:02:37
太棒了!我希望我可以将其标记为选定的答案! – Nigel 2010-05-06 15:03:16
不客气!这是一个耻辱这个问题是如此古老,但希望答案仍然可以帮助:) – 2010-05-06 15:21:33