NibblyPig
NibblyPig

Reputation: 52932

jqgrid creating a hyperlink with an id as the a parameter

I have a simple jqgrid.

colModel: [ { name: 'CatId', index: 'CatId', width: 30, align: 'left' }, ...

What I want to do is turn a column into a hyperlink like this example I find on google:

formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit'}

However I want to put the CatId as the parameter, eg:

formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=<CatId>'}

I can't seem to find any examples of how to do this, other than possibly just hooking into the loadcomplete event and going through and manually updating every row. Is there a nice way to solve this?

Upvotes: 1

Views: 732

Answers (1)

Oleg
Oleg

Reputation: 221997

The URL used by formatter: "showlink" will be constructed using formatoptions which could be baseLinkUrl, showAction, idName and addParam. The formatter "showlink" uses rowid (the id attribute of <tr> elements of the grid) for constructing the URL. The URL will be built as

baseLinkUrl + showAction + '?' + idName + '=' + rowId + addParam

So the main problem is whether the value of CatId column be used or can be used as the rowid. If you would use key: true option to the definition of CatId column then jqGrid will use the value from CatId as rowid and you could use

formatter: "showlink", formatoptions: { baseLinkUrl: "someurl.php", idName: "action" }

If the value of CatId column can't be used as rowid then I would recommend you to use formatter: "dynamicLink" instead (see jQuery.jqGrid.dynamicLink.js here). I described it in the answer.

Upvotes: 1

Related Questions