How can I get column info (name or ID) in my custom-format function?
Some code in grid.php:
$grid->dataType = 'json';
$grid->setColModel();
My custom format function
function formatPdfLink(cellValue, options, rowObject) {
var cellHtml = "<a href='" + cellValue + "' title='" + [show column Name here] + "' ><img src='../img/PDF_icon.png ' /></a> ";
return cellHtml; }
Javascript code excerpts, found in generated page (view source):
jQuery(document).ready(function($) {
jQuery('#grid').jqGrid({
"jsonReader": {
"repeatitems": false,
"subgrid": {
"repeatitems": false
}
},
"xmlReader": {
"repeatitems": false,
"subgrid": {
"repeatitems": false
}
},
"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
}
}]
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 ofname
property incolModel
. SoformatPdfLink
function used asformatter
will get third parameterrowObject
in the same simple format as original data. For examplerowObject.pdf_1
for example can be used. To access to another column you should just use the value ofname
property used incolModel
for the column.UPDATED: If you use the same custom formatter multiple times you can need to access properties of the current column. The
options
parameter will help you here.The parameter
options
contains propertiesrowId
,colModel
,gid
andpos
.this
inside of custom formatter are initialized to the DOM of the grid so you can use for example$(this).jqGrid("getGridParam", "parameterName")
or justthis.p.parameterName
to access to other options of jqGrid. The propertycolModel
contains the column definition of the current column only and not the fullcolModel
parameter.For example you can rewrite the code above to set the next from
colNames
instead ofname
propertiy in the tooltip: