setColModel();My custom format functionfunction formatPdfLink(cellValue, options, rowObject) {var cellHtml = "

JqSuite PHP: get column name or id?


How can I get column info (name or ID) in my <a href="" rel="nofollow">custom-format</a> function?

<h2>Some code in grid.php:</h2> $grid->dataType = 'json'; $grid->setColModel(); <hr /><h2>My custom format function</h2> function formatPdfLink(cellValue, options, rowObject) { var cellHtml = "<a href='" + cellValue + "' title='" + [show column Name here] + "' ><img src='../img/PDF_icon.png ' /></a> "; return cellHtml; } <h2>Javascript code excerpts, found in generated page (view source):</h2> jQuery(document).ready(function($) { jQuery('#grid').jqGrid({ <hr /> "jsonReader": { "repeatitems": false, "subgrid": { "repeatitems": false } }, "xmlReader": { "repeatitems": false, "subgrid": { "repeatitems": false } }, <hr /> "colModel": [{ { "name": "pdf_1", "index": "pdf_1", "sorttype": "string", "label": "C", "sortable": false, "width": 25, "align": "center", "search": false, "formatter": formatPdfLink, "unformat": unformatPdfLink, "editoptions": { "size": 100 }, "editable": true } }] <hr />

I have tried to use rowObject.columnName but it won't work!

NB: I am not using loadonce: true

PS: please let me know if more details are needed.


Because you use repeatitems: false format of data then the input data for the grid should be items with named properties which names are the same as the values of name property in colModel. So formatPdfLink function used as formatter will get third parameter rowObject in the same simple format as original data. For example rowObject.pdf_1 for example can be used. To access to another column you should just use the value of name property used in colModel for the column.

<strong>UPDATED</strong>: If you use the same custom formatter multiple times you can need to access properties of <em>the current</em> column. The options parameter will help you here.

<pre class="lang-js prettyprint-override">function formatPdfLink(cellValue, options, rowObject) { return "<a href='" + cellValue + "' title='" + + "' ><img src='../img/PDF_icon.png ' /></a> "; }

The parameter options contains properties rowId, colModel, gid and pos. this inside of custom formatter are initialized to the DOM of the grid so you can use for example $(this).jqGrid("getGridParam", "parameterName") or just this.p.parameterName to access to other options of jqGrid. The property colModel contains the column definition of the current column only and not the full colModel parameter.

For example you can rewrite the code above to set the next from colNames instead of name propertiy in the tooltip:

<pre class="lang-js prettyprint-override">function formatPdfLink(cellValue, options, rowObject) { //var colNames = $(this).jqGrid("getGridParam", "colNames"); var colNames = this.p.colNames; return "<a href='" + cellValue + "' title='" + colNames[options.pos] + "' ><img src='../img/PDF_icon.png ' /></a> "; }


  • How to create product of an array using values from sub-arrays
  • Variable number of parameters
  • Haskell audio output on OS X?
  • Writing a dictionary to a CSV file [duplicate]
  • Using intent ACTION_SET_ALARM to allow application to set a UNIQUE alarm
  • StreamWriter not updating its path on new day
  • Outputting SharePoint Hyperlink Column as URL
  • Doctrine/Symfony entity generator and generating entity from one table
  • Floated image with variable width and heading with background image
  • Uncaught TypeError: $(…).select2 is not a function
  • How to view images from protected folder with php?
  • How do I get HTML corresponding to current DOM tree?
  • Display images in Django
  • How to have background script and something similar to a default popup?
  • JQuery Internet Explorer and ajaxstop
  • JSON response opens as a file, but I can't access it with JavaScript
  • Python urlparse: small issue
  • Counter field in MS Access, how to generate?
  • Resize panoramic image to fixed size
  • How to set/get protobuf's extension field in Go?
  • Cassandra Data Model
  • Trying to switch camera back to front but getting exception
  • htaccess rewriting URLs with multiple forward slashes
  • Change an a tag attribute in JavaScript based on screen width
  • Javascript + PHP Encryption with pidCrypt
  • Importing jscolor library in angular 2
  • Display Images one by one with next and previous functionality
  • Websockets service method fails during R startup
  • jQuery tmpl and DataLink beta
  • Web-crawler for facebook in python
  • GridView Sorting works once only
  • Cannot Parse HTML Data Using Android / JSOUP
  • How to disable jQuery.jplayer autoplay?
  • A cron job substitute?
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Getting Messege Twice Using IMvxMessenger
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • How to load view controller without button in storyboard?