0

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 });
});
DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44
Supreeth
  • 9
  • 6

1 Answers1

0

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @Oleg...Thanks for your suggestion and time...One more problem is when the edit-dialog opens I get the cell name which i modified as a link appended with "Cellvalue"; Can you give a solution to get only cell value in the edit dialog – Supreeth Nov 17 '16 at 11:11
  • @Supreeth: I'm not sure that I understand what you mean, but I guess that you use `editable:true` in the column with the custom formatter. It's typically, that one never need to edit the column which contains the link. You should remove `editable:true` or use `editable:false`. One uses typically the properties `sortable: false, search: false, editable: false, viewable: false, hidedlg: true` in columns, which has custom formatter. – Oleg Nov 17 '16 at 11:25
  • @Supreeth: If you do need to *edit* the text inside of the link then you should provide **unformatter** (the `unformat` callback) in the column. See [the documentation](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter#unformatting). The unformatter get *the editable part* from the custom formatted cell. – Oleg Nov 17 '16 at 11:27