如何在子网格中绑定和取消绑定事件
how to bind and unbind event in subGrid
当 subGridRowExpanded 时,我有一个 jqGrid 和 SubGrid,当 SubGrid 为空时,我想取消绑定事件扩展行和图标扩展行数据。当我将一行从其他网格拖到此 SubGrid 时,我想再次为 subGridRowExpanded 绑定事件,将图标展开行添加到网格。我该怎么做?
我在加载 gridComplete 时取消绑定事件 subGridRowExpanded:
function CreateOperationGrid(styleCode, styleSize, styleColorSerial, revNo) {
Operation_Grid.jqGrid({
datatype: "json",
height: 250,
width: null,
shrinkToFit: false,
rowNum: 100000,
rownumbers: true,
gridview: false,
//==========================================
url: "/OpsLink/GetOpDetail",
caption: "Operation",
postData: {
styleCode: styleCode, size: styleSize, serial: styleColorSerial, revNo: revNo
},
//mtype: 'POST',
colModel: [
{
name: "BenchmarkTime",
index: "BenchmarkTime",
width: 95,
label: arrColname.BENCHMARKTIME,
align: "center",
search: false,
sort: false
},
{ name: "StyleCode", index: "StyleCode", hidden: true },
{ name: "StyleSize", index: "StyleSize", hidden: true },
{ name: "StyleColorSerial", index: "StyleColorSerial", hidden: true },
{ name: "RevNo", index: "RevNo", hidden: true },
{ name: "OpRevNo", index: "OpRevNo", hidden: true },
{ name: "NewPrevNo", index: "NewPrevNo", hidden: true }
],
grouping: true,
groupingView: {
groupField: ["OpGroupName"],
groupColumnShow: [false],
groupCollapse: true,
plusicon: "ace-icon fa fa-plus",
minusicon: "ace-icon fa fa-minus"
},
subGrid: true,
subGridRowExpanded: function (subgridId, rowId) {
var row = Operation_Grid.getRowData(rowId);
var sCode = row.StyleCode;
var subgridTableId = subgridId + "_t";
jQuery("#" + subgridId).html("<table id='" + subgridTableId + "' class='scroll'></table>");
jQuery("#" + subgridTableId).jqGrid({
url: "/OpsLink/GetProtBomPattern?styleCode=" + sCode,
datatype: "json",
page: 1,
colModel: [
{ label: arrOpChilName.OpRevNo, name: "OpRevNo", index: "OpRevNo", width: 80 },
{ label: arrOpChilName.OpSerial, name: "OpSerial", index: "OpSerial", width: 80 },
{ label: arrOpChilName.OpType, name: "OpType", index: "OpType", width: 80 },
{ label: arrOpChilName.ConSumUnit, name: "ConSumUnit", index: "ConSumUnit", width: 80 },
{ label: arrOpChilName.UnitConSumTion, name: "UnitConSumTion", index: "UnitConSumTion", width: 80 },
{ label: arrOpChilName.PieceQty, name: "PieceQty", index: "PieceQty", width: 80 }
],
viewrecords: true,
height: "100%",
rownumbers: true,
multiselect: true,
pager: "#jqGridPager" + "_" + subgridId
});
},
subGridOptions: {
plusicon: "ace-icon fa fa-plus",
minusicon: "ace-icon fa fa-minus",
openicon: "ui-icon-carat-1-sw",
expandOnLoad: false,
selectOnExpand: false,
reloadOnExpand: false
},
gridComplete: function () {
Operation_Grid.find('tr[role="row"]').addClass("ui-droppable");
$('td[aria-describedby="Operation_Grid_NewPrevNo"]').each(function () {
var x = $(this).html();
if (x === " ") {
$(this).parent().find('td[aria-describedby="Operation_Grid_subgrid"]').unbind("click").html("");
}
});
}
});
}
我想再次注册活动:
Operation_Grid.find('tr[id="' + rowDropTo + '"]').find('td[aria-describedby="Operation_Grid_subgrid"]').bind("click").html('<a style="cursor:pointer;"><span class="ui-icon ui-icon-plus"></span></a>');
但是当我点击图标时它没有 运行 函数 subGridRowExpanded。请帮助,谢谢
如果您使用 Guriddo jqGrid, please look at our demo example here
编辑:针对您的情况的另一种可能的解决方案是仅显示和隐藏图标(点击绑定的 href 标记)而不是绑定取消绑定事件。
经过两天的研究,我已经像这样重新绑定了susses。
- 删除之前将其放入数组中:
currChild[id] = $(this).parent().find('td[aria-describedby="Operation_Grid_subgrid"]').clone(true, true);
$(this).parent().find('td[aria-describedby="Operation_Grid_subgrid"]').unbind("click").html("");
再装箱。
Operation_Grid.find('tr[id="' + rowDropTo + '"]').find('td[aria-describedby="Operation_Grid_subgrid"]').replaceWith(currChild[rowDropTo]);
当 subGridRowExpanded 时,我有一个 jqGrid 和 SubGrid,当 SubGrid 为空时,我想取消绑定事件扩展行和图标扩展行数据。当我将一行从其他网格拖到此 SubGrid 时,我想再次为 subGridRowExpanded 绑定事件,将图标展开行添加到网格。我该怎么做?
我在加载 gridComplete 时取消绑定事件 subGridRowExpanded:
function CreateOperationGrid(styleCode, styleSize, styleColorSerial, revNo) {
Operation_Grid.jqGrid({
datatype: "json",
height: 250,
width: null,
shrinkToFit: false,
rowNum: 100000,
rownumbers: true,
gridview: false,
//==========================================
url: "/OpsLink/GetOpDetail",
caption: "Operation",
postData: {
styleCode: styleCode, size: styleSize, serial: styleColorSerial, revNo: revNo
},
//mtype: 'POST',
colModel: [
{
name: "BenchmarkTime",
index: "BenchmarkTime",
width: 95,
label: arrColname.BENCHMARKTIME,
align: "center",
search: false,
sort: false
},
{ name: "StyleCode", index: "StyleCode", hidden: true },
{ name: "StyleSize", index: "StyleSize", hidden: true },
{ name: "StyleColorSerial", index: "StyleColorSerial", hidden: true },
{ name: "RevNo", index: "RevNo", hidden: true },
{ name: "OpRevNo", index: "OpRevNo", hidden: true },
{ name: "NewPrevNo", index: "NewPrevNo", hidden: true }
],
grouping: true,
groupingView: {
groupField: ["OpGroupName"],
groupColumnShow: [false],
groupCollapse: true,
plusicon: "ace-icon fa fa-plus",
minusicon: "ace-icon fa fa-minus"
},
subGrid: true,
subGridRowExpanded: function (subgridId, rowId) {
var row = Operation_Grid.getRowData(rowId);
var sCode = row.StyleCode;
var subgridTableId = subgridId + "_t";
jQuery("#" + subgridId).html("<table id='" + subgridTableId + "' class='scroll'></table>");
jQuery("#" + subgridTableId).jqGrid({
url: "/OpsLink/GetProtBomPattern?styleCode=" + sCode,
datatype: "json",
page: 1,
colModel: [
{ label: arrOpChilName.OpRevNo, name: "OpRevNo", index: "OpRevNo", width: 80 },
{ label: arrOpChilName.OpSerial, name: "OpSerial", index: "OpSerial", width: 80 },
{ label: arrOpChilName.OpType, name: "OpType", index: "OpType", width: 80 },
{ label: arrOpChilName.ConSumUnit, name: "ConSumUnit", index: "ConSumUnit", width: 80 },
{ label: arrOpChilName.UnitConSumTion, name: "UnitConSumTion", index: "UnitConSumTion", width: 80 },
{ label: arrOpChilName.PieceQty, name: "PieceQty", index: "PieceQty", width: 80 }
],
viewrecords: true,
height: "100%",
rownumbers: true,
multiselect: true,
pager: "#jqGridPager" + "_" + subgridId
});
},
subGridOptions: {
plusicon: "ace-icon fa fa-plus",
minusicon: "ace-icon fa fa-minus",
openicon: "ui-icon-carat-1-sw",
expandOnLoad: false,
selectOnExpand: false,
reloadOnExpand: false
},
gridComplete: function () {
Operation_Grid.find('tr[role="row"]').addClass("ui-droppable");
$('td[aria-describedby="Operation_Grid_NewPrevNo"]').each(function () {
var x = $(this).html();
if (x === " ") {
$(this).parent().find('td[aria-describedby="Operation_Grid_subgrid"]').unbind("click").html("");
}
});
}
});
}
我想再次注册活动:
Operation_Grid.find('tr[id="' + rowDropTo + '"]').find('td[aria-describedby="Operation_Grid_subgrid"]').bind("click").html('<a style="cursor:pointer;"><span class="ui-icon ui-icon-plus"></span></a>');
但是当我点击图标时它没有 运行 函数 subGridRowExpanded。请帮助,谢谢
如果您使用 Guriddo jqGrid, please look at our demo example here
编辑:针对您的情况的另一种可能的解决方案是仅显示和隐藏图标(点击绑定的 href 标记)而不是绑定取消绑定事件。
经过两天的研究,我已经像这样重新绑定了susses。
- 删除之前将其放入数组中:
currChild[id] = $(this).parent().find('td[aria-describedby="Operation_Grid_subgrid"]').clone(true, true); $(this).parent().find('td[aria-describedby="Operation_Grid_subgrid"]').unbind("click").html("");
再装箱。
Operation_Grid.find('tr[id="' + rowDropTo + '"]').find('td[aria-describedby="Operation_Grid_subgrid"]').replaceWith(currChild[rowDropTo]);