【发布时间】:2015-05-20 09:03:55
【问题描述】:
jQuery("#grid").jqGrid({
url:call_url,
datatype: "json",
height: 'auto',
rowNum: 20,
rowList: [20,30,40],
colNames:[<?php echo $col;?>],
colModel:[
{name:'USER_ID',index:'USER_ID', align:'center',search:false,hidden:true,key:true},
{name:'PROJECT_NAME',index:'PROJECT_NAME', align:'center',search:false,hidden: true},
{name:'EMP_NAME',index:'EMP_NAME', sortable:true,summaryType:'count',summaryTpl : 'Total ({0}) Resource Hours' },
<?php for($i=1;$i<=count($cal_arr);$i++) {?>
{name:'<?php echo $i;?>',index:'<?php echo $i;?>',search:false,align:"center",sortable:false ,width:80 },
<?php } ?>
],
pager: "#page",
multiselect: true,
shrinkToFit :true,
autowidth: true,
viewrecords: true,
grouping: true,
groupingView : { groupField : ['PROJECT_NAME'],
groupColumnShow : [false],
groupText : ['<b>{0}</b>'],
groupCollapse : false,
groupOrder: ['asc'],
groupSummary : [true],
showSummaryOnHide: true,
groupDataSorted : true },
sortname: 'EMP_NAME',
caption: "Programatically block selection of some grid row',
gridComplete: function () {
var recs = $("#grid").getGridParam("records");
$( ".mycontent" ).remove();
if (recs == 0 || recs == null) {
$('#grid').after("<div class='mycontent' style='color:red;text-align:center'>No Record Found</div>");
$("#btn_submit").hide();
}
},
loadComplete: function () {
$("#cb_grid").click();
},
rowattr: function (item) {
if (parseInt(item.ID) == 1) {
return {"class": "ui-state-disabled ui-jqgrid-disablePointerEvents"};
}
},
//prevent selection of disabled rows
beforeSelectRow: function (rowid, e) {
if ($(e.target).closest("tr.jqgrow").hasClass("ui-state-disabled")) {
return false; // not allow select the row
}
return true; // allow select the row
}
})
上面的代码是这样做的
必填项
使用带有multiselect:true 的jqGrid 如何设置在页面加载时默认检查的每一行? jQgrid 版本 - 4.6
【问题讨论】:
-
请包括 always 哪个 jqGrid 分支以及您使用的 jqGrid 版本。不同的版本有不同的可能性。如果您仍然使用 jqGrid 4.6,那么您可以加载所有选择的数据,如果
datatype: "local"、deselectAfterSort: false、multiselect: true和selarrrow数组填充了需要在加载期间选择的行的 ID。 -
@Oleg,在我的例子中是
datatype: "json",和multiselect: true。如何获取行的 id 并在第一次加载页面时默认保持选中状态?