I want to get the edit dialog on click of a link..I have attached the code

混江龙づ霸主 提交于 2020-01-07 02:48:12

问题


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 });
});

回答1:


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".

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

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

where

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

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.



来源:https://stackoverflow.com/questions/40648021/i-want-to-get-the-edit-dialog-on-click-of-a-link-i-have-attached-the-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!