jQgrid:multiselect true-在页面加载时默认检查每一行 [英] jQgrid: multiselect true - make each row checked by default on page load
问题描述
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
}
})
上面的代码可以做到
必填项是
将jqGrid与multiselect:true
一起使用时,如何设置页面加载时默认检查的每一行? jQgrid版本-4.6
Using jqGrid with multiselect:true
how to set each row checked by default on page load ? jQgrid Version - 4.6
推荐答案
如果将jqGrid 4.6与datatype: "json"
一起使用,并且没有loadonce: true
选项,那么您的可能性就很小.您必须枚举网格的所有多选复选框,然后在此处选择.所以你可以做
If you use jqGrid 4.6 with datatype: "json"
and no loadonce: true
option then you have not so much possibilities. You have to enumerate all multiselect checkboxes of the grid and select there. So you can do
$("#cb_grid").click(); // "grid" is the grid id
例如,在loadComplete
回调内部的
.如果您考虑所有情况,则可能会添加更多其他条件,因为loadComplete
将在排序,分页等操作时被调用.
inside of loadComplete
callback for example. If you would think about all cases you will probably add more additional criteria, because loadComplete
will be called on sorting, paging and so on.
更新:您的代码在rowattr
内有$('.cbox').attr('checked', true);
行.这样,您就不会更改该行的复选框(该复选框尚不存在).取而代之的是,在列标题的复选框上使用错误的值true
而不是"checked"
设置checked
属性.您应该删除该行,以便能够使用我建议您使用的代码:
UPDATED: You code have $('.cbox').attr('checked', true);
line inside of rowattr
. In the way you don't change the checkbox of the row, which is not yet exist. Instead of that you set checked
attribute with wrong value true
instead of "checked"
on the checkbox of the column header. You should remove the line to be able to use the code which I suggested you:
loadComplete: function () {
$("#cb_" + this.id).click();
},
rowattr: function (item, rd, rowid) {
//$('.cbox').attr('checked', true);
if (parseInt(rowid) === 10) {
return {"class": "ui-state-disabled ui-jqgrid-disablePointerEvents"};
}
},
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
}
请参阅演示: http://jsfiddle.net/OlegKi/aagxejj5/4/
这篇关于jQgrid:multiselect true-在页面加载时默认检查每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!