如何在 subGrid 中绑定和取消绑定事件
Posted
技术标签:
【中文标题】如何在 subGrid 中绑定和取消绑定事件【英文标题】:how to bind and unbind event in subGrid 【发布时间】:2018-01-15 16:21:51 【问题描述】:当 subGridRowExpanded 时我有一个 jqGrid 和 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 功能。请帮忙,谢谢
【问题讨论】:
【参考方案1】:经过两天的研究,我一直像这样重新绑定 susses。
-
在将 pus 移除到数组中之前:
currChild[id] = $(this).parent().find('td[aria- describeby="Operation_Grid_subgrid"]').clone(true, true); $(this).parent().find('td[aria- describeby="Operation_Grid_subgrid"]').unbind("click").html("");
重新装箱。
Operation_Grid.find('tr[id="' + rowDropTo + '"]').find('td[aria- describeby="Operation_Grid_subgrid"]').replaceWith(currChild[rowDropTo]);
【讨论】:
【参考方案2】:如果您使用Guriddo jqGrid,请查看我们的demo example here
编辑:针对您的情况,另一种可能的解决方案是仅显示和隐藏图标(在绑定中单击的 href 标记),而不是绑定取消绑定事件。
【讨论】:
以上是关于如何在 subGrid 中绑定和取消绑定事件的主要内容,如果未能解决你的问题,请参考以下文章
如何从 jQuery 中的“滚动”事件中取消绑定所有先前添加的事件? [复制]