您可以在此处每行使用动作格式化程序,并在formatOptions中将“编辑”和“删除”按钮设置为false,如下所示:
formatoptions: {editbutton:false,delbutton:false}}并遵循以下两个演示:
http://www.ok-soft-gmbh.com/jqGrid/Admin3.htm
http://ok-soft-gmbh.com/jqGrid/TestSamle/Admin1.htm
这些自定义按钮的点击事件会显示您的警报:
编辑
var getColumnIndexByName = function (grid, columnName) { var cm = grid.jqGrid('getGridParam', 'colModel'), i, l = cm.length; for (i = 0; i < l; i++) { if (cm[i].name === columnName) { return i; // return the index } } return -1; },function () { var iCol = getColumnIndexByName(grid, 'act'); $(this).find(">tbody>tr.jqgrow>td:nth-child(" + (iCol + 1) + ")") .each(function() { $("<div>", { title: "Custom", mouseover: function() { $(this).addClass('ui-state-hover'); }, mouseout: function() { $(this).removeClass('ui-state-hover'); }, click: function(e) { alert("'Custom' button is clicked in the rowis="+ $(e.target).closest("tr.jqgrow").attr("id") +" !"); } }).css({"margin-right": "5px", float: "left", cursor: "pointer"}) .addClass("ui-pg-div ui-inline-custom") .append('<span ></span>') .prependTo($(this).children("div")); }); }如果您检查此代码,我试图通过将列名设置为“ act”来查找索引值,则可以通过提供其他列名来获取其他任何列的索引。
var iCol = getColumnIndexByName(grid, 'Demo'); and the rest of the pre will be same for you. //demo is the column name where u want to add custom button
并为该按钮编写点击事件。
让我知道这对您是否有用。



