是否有一种类似于单选按钮的复选框获得行为的方法?http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridWidthRadioButton2.htm包含复选框,用于选择/取消选择所有选项。该行上的行选择和复选框可能不会链接,就像单选按钮示例中的情况一样。
更新:
这是我的片段:
$("#list").jqGrid({
datatype: "local",
data: mydata,
colNames: ["Client", "Date", "Amount", "Tax", "Total", "Shipped via", "Notes"],
colModel: [
{name: "name", width: 70, frozen: true},
{name: "invdate", width: 80, align: "center", sorttype: "date",
formatter: "date", formatoptions: {newformat: "d-M-Y"}, datefmt: "d-M-Y"},
{name: "amount", width: 75, formatter: "number", sorttype: "number", align: "right"},
{name: "tax", width: 55, formatter: "number", sorttype: "number", align: "right"},
{name: "total", width: 65, formatter: "number", sorttype: "number", align: "right"},
{name: "ship_via", width: 100, align: "center", formatter: "select",
edittype: "select", editoptions: {value: "FE:FedEx;TN:TNT;IN:Intim", defaultValue: "IN"}},
{name: "note", width: 70, sortable: false}
],
rowNum: 10,
rowList: [5, 10, 20],
pager: "#pager",
gridview: true,
rownumbers: true,
sortname: "invdate",
viewrecords: true,
sortorder: "desc",
caption: "Handling of changing of chechboxes in the grid",
height: "auto",
multiselect: true,
multiboxonly: true,
beforeSelectRow: function (rowid, e) {
var $target = $(e.target), $td = $target.closest("td"),
iCol = $.jgrid.getCellIndex($td[0]),
colModel = $(this).jqGrid("getGridParam", "colModel");
if (iCol >= 0 && $target.is(":checkbox")) {
return false;
}
return true;
},
onSelectRow: function (rowid, isSelected, event) {
var rowData = $("#list").jqGrid("getRowData", rowid);
var checkbox = jQuery(this).find('#' + rowid + ' input#jqg_list_'+rowid+'[type=checkbox]');
if ($(checkbox).is(':checked')) {
$(checkbox).attr('checked', false);
}
},
});
http://jsfiddle.net/yNw3C/12696/
正如您所看到的,问题是当我单击先前选中的行时,它将取消选中复选框。
发布于 2016-01-20 22:57:31
单击行将不会选中您的复选框,除非有代码可以显式地实现这一点。因此,我将猜测,您遇到的问题是,当您单击复选框时,您的行的onclick处理程序被调用。为了防止这种情况,添加stopPropegation():
$('table checkbox').click(function(event) {
event.stopPropagation();
});
还有stopImmediateProgagation(),但是stopPropagation()对您的情况应该足够了。
如果这不能纠正问题,请发布一个JsFiddle或提供一个活动链接,以便更容易地看到您的代码正在做什么。
UPDATE:您的onRowSelect处理程序(第60行)针对行中的所有复选框,如果您更新第64行以针对您感兴趣的特定复选框,它将按照您的预期工作:
var checkbox = jQuery(this).find('#' + rowid + ' input#jqg_list_'+rowid+'[type=checkbox]');
而不是
var checkbox = jQuery(this).find('#' + rowid + ' input[type=checkbox]');
UPDATE2:
是的,这并不能完全解决你的问题。我在你的小提琴上尝试了几种方法,似乎每一种合理的方法都试图解决这个问题,结果却是与插件做了太多的斗争。根据文档,'multiselect: true‘和'multiboxonly: true’选项应该足够了。我会向插件维护人员提交一个bug报告。
发布于 2016-12-15 18:55:29
$(function () {
$('#toggleAll').click(function (event) {
var checked = event.target.checked;
$("input[name='checkIds']").each(function (e) {
this.checked = checked;
})
event.stopPropagation();
});
}
var chkBoxs = "<input type='checkbox' id='toggleAll' />";
var colNames = [chkBoxs];
当我在jqGrid中使用复选框组件时,我也遇到了同样的问题。上面的代码段是解决问题的有效方法。在实际中,js的事件机制导致了故障。
https://stackoverflow.com/questions/34911548
复制相似问题