0

I am using a custom formatter to create hyperlinks in one of the columns of my grid.

In my code, there are cases when I need to disable the selected row. The row disabling works as I want it to, but the hyperlink for that row is not disabled. I can not select the row and all the other column values are displayed as grey colored to indicate that the row is disabled. The only column whose content does not change color is the one having links.

Any ideas on how to disable links?

This is my loadComplete function:

    loadComplete: function (data) {

           var ids =jQuery("#list").jqGrid('getDataIDs');

            for(var i=0;i < ids.length;i++){

                var rowId = ids[i];
                var mod = jQuery("#list").jqGrid('getCell',ids[i],'mod');

                if(mod=='y'){

                jQuery("#jqg_list_"+rowId).attr("disabled", true);
                $("#list").jqGrid('setRowData',ids[i],false, {weightfont:'bold',color:'silver'});

                var iCol = getColumnIndexByName.call(this, 'adate');

                $(this).jqGrid('doInEachRow', function (row, rowId, localRowData) {
                    $(row.cells[iCol]).children("a").click(function (e) {
                        e.preventDefault();
                        // any your code here
                        alert("No Good");
                        return false;
                    });
                });

                    }
                }

            }

I want the links disabled in all the rows where the value of the column mod=y

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
AbtPst
  • 7,778
  • 17
  • 91
  • 172

1 Answers1

0

You can try to use onClick callback of dynamicLink formatter described here, here and here. It gives you maximum flexibility. Inside of onClick callback you can test something like $(e.target).closest("tr.jqgrow").hasClass("not-editable-row") and just do nothing in the case.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thanks @Oleg ! i tried using doInEachRow but nothing happens. kindly refer to my modidified code in the edit – AbtPst Jul 26 '13 at 15:42
  • isn't there a way to alter the value inside the cell ? if i can access the cell data, can i change the onclick property ? i know that all i have to do is return false from the onclick function of the link – AbtPst Jul 26 '13 at 15:51
  • @user2334092: I mean that you should use `formatter: "dynamicLink"` instead of `formatter: "showlink"`. By the way I hope you know that to go to an URL you can just assign new value to `window.location` or `window.location.href`. You can do this inside of `onClick` callback. – Oleg Jul 26 '13 at 16:07
  • thanks @Oleg ! i was able to do it inside the formatter itself ! like this – AbtPst Jul 26 '13 at 17:06
  • function myLinkFormatter(cellvalue, options, rowObject) { if(rowObject[4]=="y") { return "" + cellvalue + ""; } else return "" + cellvalue + ""; } – AbtPst Jul 26 '13 at 17:07