jqgrid中带有自定义函数调用的超链接/按钮
hyperlink / button with custom function call in jqgrid
我想在jqgrid的每一行添加一个超链接/按钮,它会触发一个自定义javascript函数。厌倦了各种各样的尝试。
jQuery('#ProductListGrid').jqGrid({
url: '/Product/ProductListGrid',
datatype: 'json',
multiselect: true,
height: 250,
autowidth: true,
mtype: 'GET',
loadComplete: addlinks,
colNames: ['ProductId', 'ProductName', 'edit'],
colModel: [
{ name: 'ProductId', index: 'ProductId',key:true, width: 70, hidden: true, editable: true, size: 5 },
{ name: 'ProductName', index: 'ProductName', width: 70, editable: true },
{ name: 'edit', index: 'edit', width: 70},
],
pager: jQuery('#ProductListGrid_pager'),
});
function addlinks() {
var ids = jQuery("#ProductListGrid").getDataIDs();
alert(ids);
for (var i = 0; i < ids.length; i++) {
be = "<a href='#' style='height:25px;width:120px;' type='button' title='Slet' onclick='"ff()'" >Slet</>";
jQuery("#ProductListGrid").jqGrid('setCell', ids[i],'edit','', { act: be });
}
//for (var i = 0; i < ids.length; i++) {
// jQuery("#ProductListGrid").setCell(i, 'edit', '<a href="#">edit</edit>');
//}
}
function ff()
{
alert("hi");
}
addlinks in中的代码正在执行,但列中没有显示任何内容。我也尝试使用自定义格式,但我无法显示自定义文本"编辑"和链接单击不触发js方法。
您需要像下面这样调用编辑列的格式化器:
将formatter: addLink
添加到最后一列:
colModel: [
{ name: 'ProductId', index: 'ProductId',key:true, width: 70, hidden: true, editable: true, size: 5 },
{ name: 'ProductName', index: 'ProductName', width: 70, editable: true },
{ name: 'edit', index: 'edit', width: 70,formatter: addLink},
]
添加javascript函数:
function addLink(cellvalue, options, rowObject)
{
//to get row Id
alert(options.rowId);
// to get product Id
alert(rowObject.ProductId);
return "<a href='#' style='height:25px;width:120px;' type='button' title='Slet' onclick='"ff()'" >Slet</a>";
}
关于格式化器的更多信息请点击这里
相关文章:
- 用Javascript按钮替换Javascript超链接
- 如何使用jQuery获得超链接上的焦点或文本字段焦点上的按钮
- 我让一个图像看起来像一个可点击的按钮,但现在当我点击它时,它不会起到超链接的作用
- 使用 JavaScript 引用按钮的超链接
- 如何使超链接像按钮一样工作
- 创建一个超链接(或按钮),用于执行 python 脚本,然后在脚本完成时重定向
- 通过jQuery单击另一个按钮时动态地将数据添加到超链接
- 使用超链接而不是提交按钮提交 AJAX 表单时出现问题
- 如何创建ctrl按钮超链接
- 通过中介函数使用超链接而不是按钮来提交表单是不起作用的
- javascript函数调用没有点击超链接按钮的原因
- 使用jquery下载按钮的超链接
- 在WEB应用程序中为已选择的选项卡隐藏超链接按钮
- Silverlight超链接按钮和UNC路径
- <输入类型=按钮上的超链接不起作用
- Aspx页面通过按钮打开超链接
- 将超链接转换为按钮
- 如何在单击提交按钮时验证超链接和复选框
- jqgrid中带有自定义函数调用的超链接/按钮
- 如何使用jQuery更改超链接/按钮