html-Link-Spalte in jqGrid

Lesezeit: 2 Minuten

Ist es möglich, einen HTML-Link in einer Spalte mit jqGrid zu haben, ich kann kein Beispiel in der Dokumentation finden?

  • @djangofan jQuery und ExtJs sind zwei verschiedene Frameworks und haben nichts mit Grids zu tun. Ich verstehe nicht, was Ihr Kommentar mit dieser Frage zu tun hat.

    – Charles Boyung

    11. Mai 2012 um 20:37 Uhr

Hier ist das Beispiel einer colModel-Konfiguration von Craigs Link zur jqGrid-Formatierungshilfe. Es gibt den Formatierer als an Link zeigen und die url und params werden mit angegeben Formatoptionen.

colModel: [ {name:'myname', 
             edittype:'select', 
             formatter:'showlink', 
             formatoptions:{baseLinkUrl:'someurl.php', addParam: '&action=edit'}

  • Thanks for posting the sample. Always helpful 🙂

    – Dan

    May 7, 2010 at 8:57

  • It 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, 2011 at 4: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="https://stackoverflow.com/Controller/Action/" + options.rowId + "" >Click here</a>";
}   

Look in the rowdata for the data returned by your query. Hope this helps someone!

  • Use 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, 2011 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, 2012 at 0:24

user avatar
Craig Stuntz

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

  • link with the answer is broken

    – IT ppl

    Nov 10, 2012 at 10:51

  • link has since been fixed

    – ZAD-Man

    Sep 9, 2015 at 21:02

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

user avatar
yei

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

user avatar
user214553

in xml I use entity &lt; instead of < in the a tag like this
&lt;a href=”https://stackoverflow.com/questions/1166076/dest”>my link&lt;/a> and works fine with jqgrid 3.6

1187530cookie-checkhtml-Link-Spalte in jqGrid

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy