我想在单击链接时获得编辑对话框..我已附上代码 [英] I want to get the edit dialog on click of a link..I have attached the code

查看:85
本文介绍了我想在单击链接时获得编辑对话框..我已附上代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是ColModel:

Here is the ColModel:

{name: "FirstName", index: "FirstName", width: 100, sortable: true,      editable:true, formatter: GetRow}             

function GetRow(cellvalue, options, rowObject) {
     return "<a href='#' class='GetLink'>" + cellvalue + "</a>";
}
$('.GetLink').click(function (rowid) {
     var row = $('#grid').jqGrid('getGridParam', 'selrow');
     $('#grid').jqGrid('editGridRow', row, { recreateForm: true, closeAfterEdit: true, closeOnEscape: true, reloadAfterSubmit: false });
});

推荐答案

您当前的代码有一些缺点.我建议您使用带有选项formatoptions: { editformbutton: true }formatter: "actions"而不是自定义格式化程序来创建编辑/删除按钮(请参见旧答案详细介绍了该方法,并提供了的用法.

Your current code has some disadvantages. I would recommend you to use formatter: "actions" with the option formatoptions: { editformbutton: true } instead of custom formatter to create edit/delete buttons (see the old documentation, which describes the options of the formatter, for example delbutton: false, which remove Delete button) in every row of the grid. The old answer describes the approach more detailed and provides the demo, which demonstrates the usage of formatter: "actions".

如果您愿意使用自定义格式器,则可以使用<span>而不是<a>:

If you would do prefer to use custom formatter, then you could use <span> instead of <a>:

return "<span class='GetLink'>" + cellvalue + "</span>";

其中

.GetLink { text-decoration: underline; cursor: pointer; }

我会建议您在网格上使用 one 点击处理程序,而不是使用$('.GetLink').click来为每个hiperlink注册单独点击处理程序. jqGrid已经注册了这样的单击处理程序,并允许针对beforeSelectRow回调使用您的自定义操作.它节省了Web浏览器的内存,并允许进行一次绑定,而不是在每次重新加载网格后重新应用绑定.有关更多详细信息,请参见答案.

Instead of usage $('.GetLink').click, which register separate click-handler for every hiperlink, I'd recommend you to use one click-handler on the grid. jqGrid register already such click-handler and allows to use your custom actions with respect of beforeSelectRow callback. It saves memory of the web browser and allows to make binding once instead of reapplying binding after every reloading of the grid. See the answer for more details.

可能对您有帮助的其他答案:

Other answers, which could be helpful for you: this one and this one.

这篇关于我想在单击链接时获得编辑对话框..我已附上代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆