Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this in different ways. The first one is to use <code>formatter:'showlink'</code> in the form like the following</p> <pre><code>formatoptions: { baseLinkUrl: 'javascript:', showAction: "MyBase.GetAndShowUserData(jQuery('#list'),'", addParam: "');" } </code></pre> <p>(see my <a href="https://stackoverflow.com/questions/3605197/send-ajax-request-from-jqgrid-showlink-click/3608421#3608421">old answer</a> for details). It will produce the <code>&lt;a&gt;</code> link with</p> <pre><code>href="javascript:MyBase.GetAndShowUserData(jQuery('#userlist'),'?id=rowId');" </code></pre> <p>where <code>rowId</code> will be the id of the corresponding grid row. Inside of your custom <strong>global</strong> function <code>MyBase.GetAndShowUserData</code> you should cut <code>"?id="</code> prefix from the second parameter. So you will be able to access the grid and you will know the selected id.</p> <p>One more way is to write you own <a href="http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter" rel="nofollow noreferrer">custom formatter</a> instead of the usage of <code>formatter:'showlink'</code>.</p> <p>The main disadvantage of both approaches in my opinion is the usage of <strong>global</strong> functions. Moreover I prefer to follow concept of <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript" rel="nofollow noreferrer">unobtrusive JavaScript</a>. So I can suggest you another way from <a href="http://www.trirand.com/blog/?page_id=393/help/format-link-for-url-rewriting/#p21162" rel="nofollow noreferrer">my answer</a> on the trirand forum. The idea is to use predefined formatter <code>showlink</code> with '#' as the value of <code>href</code> attribute and <strong>to make binding</strong> to the <code>click</code> event of the link inside of <code>loadComplete</code> function:</p> <pre><code>colModel: [ { name: 'Subcategory', formatter:'showlink',formatoptions:{baseLinkUrl:'#'} ... loadComplete: function() { var myGrid = $("#list"); var ids = myGrid.getDataIDs(); for (var i = 0, idCount = ids.length; i &lt; idCount; i++) { $("#"+ids[i]+" a",myGrid[0]).click(function(e) { var hash=e.currentTarget.hash;// string like "#?id=0" if (hash.substring(0,5) === '#?id=') { var id = hash.substring(5,hash.length); var text = this.textContent || this.innerText; alert("clicked the row with id='"+id+"'. Link contain '"+text+"'"); location.href="http://en.wikipedia.org/wiki/"+text; } e.preventDefault(); }); } } </code></pre> <p>see live demo <a href="http://www.ok-soft-gmbh.com/jqGrid/UnobtrusiveLinks.htm" rel="nofollow noreferrer">here</a>. In the demo if you click on the text like "Physics" in the table it will be opened the url <a href="http://en.wikipedia.org/wiki/Physics" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Physics</a> which will be build dynamical. I included an additional alert to show how to decode information about the row id additionally.</p> <p><strong>UPDATED:</strong> Look at the improved code (from the performance side) of <code>loadComplete</code> in <a href="https://stackoverflow.com/questions/5010761/linking-from-a-column-value-in-jqgrid-to-a-new-page-using-get/5017528#5017528">another answer</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload