Is it possible have a html link in a column with jqGrid, I can't find any example in the documentation?
6 Answers
Here's the sample colModel configuration from Craig's link to jqGrid formatting help. It specifies the formatter as showLink and the url and params are specified with formatoptions.
colModel: [ {name:'myname',
edittype:'select',
formatter:'showlink',
formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit'}

- 947
- 2
- 9
- 16
-
-
4It appends id=bla to base url, can I change the id to something else like data_id or record_id? I found how to do this formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit', idName='record_id'} – digz6666 Feb 15 '11 at 04:11
Sorry to post to an old question, but here is another option that worked for me: simply create a custom formatter and return an anchor tag (a good option if you need really granular control of the link):
function returnMyLink(cellValue, options, rowdata, action)
{
return "<a href='/Controller/Action/" + options.rowId + "' >Click here</a>";
}
Look in the rowdata for the data returned by your query. Hope this helps someone!

- 5,970
- 4
- 24
- 21
-
1Use this one where you want the id part of the link and not a parameter. eg. you want /mylink/123/ not /mylink?id=123 – PhoebeB Sep 20 '11 at 11:16
-
this approach with custom formater will require further work in editoptions cause full output will be put in there as value. – Email Feb 20 '12 at 00:24
Yes, use a formatter, either a custom formatter or Predefined Formatter.

- 147,647
- 23
- 218
- 272

- 125,891
- 12
- 252
- 273
within the json data i am using for the grid, i just send html code back with a href tag in, that works for me

- 2,316
- 6
- 30
- 40
-
Worked for me. In MVC controller action something like this when creating the json object worked for me: `@"" + p.Name + ""` This however breaks the sorting as it encounter PeopleKey before Name. But I'm sure there is another work around for this. – AaronLS Apr 19 '12 at 17:30
-
1Managed to fix the sorting. Have to add another column that is just the text to sort on which is hidden `{ name: 'Name', index: 'Name', hidden: true},` and then reference that column name in the visible column's index: `{width: 190, name: 'NameUrl', index: 'Name'},` – AaronLS Apr 27 '12 at 21:33
If you use xml data, you can add a dummy column in your query to display it in the grid
grid:
colModel :[{name:'EDIT',edittype:'select',formatter:'showlink', width:5,xmlmap:"Edit",formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit'}},
query:
select f1,f2,f3, 'Edit' as Edit FROM table

- 31
- 1
in xml I use entity < instead of < in the a tag like this <a href="dest">my link</a> and works fine with jqgrid 3.6

- 11
- 1