1

How do I set the display text on a link column in jqGrid. I want the text in every column to just say "View" with the link containing the specific Id. Here is what I currently have, but the Id get displayed in the column instead of the text "View". I was hoping to do it without passing the link html in the json returned data.

{ name: 'myId', index: 'View', edittype: 'select', formatter: 'showlink', formatoptions: {  baseLinkUrl: 'Consumer/Details', idName: 'myId'} }

My json object getting return looks like this:

select new
                                   {
                                       myId = obj.myId.ToString(),
                                       Date = String.Format("{0:d}", obj.Date),
                                       Description = obj.Description,
                                       View = "View"
                                   }
ctrlalt313373
  • 3,935
  • 7
  • 36
  • 40

1 Answers1

2

If I correct understand your question you can just use the following simple custom formatter instead of 'showlink' predefined formatter:

formatter: function (cellvalue, options, rowObject) {
    return '<a href="Consumer/Details?myId=' + opts.rowId + '">View</a>';
}

If you need to include some additional information in the URL of href you can use properties of the rowObject (rowObject.Date, rowObject.Description) or replace opts.rowId to the cellvalue or rowObject.myId.

You should additionally verify whether the property edittype: 'select' which you use is correct for the column. It looks like Cut&Paste error, especially because you don't use editable: true property.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • shouldn't be 'function formatter' instead of 'formatter: function'? I am new to javascript, just found that 'function formatter' works for me. – Paul L Sep 04 '11 at 23:35
  • 1
    @pstar: No. 'formatter' is the property name. it can be a function. One can define anonymous function as the property value. So you should just try the code from the answer and place the `formatter` property in the column where you use currently `formatter: 'showlink'`. – Oleg Sep 04 '11 at 23:40