html link column in jqGrid

2019-02-01 06:12发布

问题:

Is it possible have a html link in a column with jqGrid, I can't find any example in the documentation?

回答1:

Yes, use a formatter, either a custom formatter or Predefined Formatter.



回答2:

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'}


回答3:

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!



回答4:

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



回答5:

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


回答6:

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



标签: jquery jqgrid