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: falseformat of data then the input data for the grid should be items with named properties which names are the same as the values ofnameproperty incolModel. SoformatPdfLinkfunction used asformatterwill get third parameterrowObjectin the same simple format as original data. For examplerowObject.pdf_1for example can be used. To access to another column you should just use the value ofnameproperty used incolModelfor the column.UPDATED: If you use the same custom formatter multiple times you can need to access properties of the current column. The
optionsparameter will help you here.The parameter
optionscontains propertiesrowId,colModel,gidandpos.thisinside of custom formatter are initialized to the DOM of the grid so you can use for example$(this).jqGrid("getGridParam", "parameterName")or justthis.p.parameterNameto access to other options of jqGrid. The propertycolModelcontains the column definition of the current column only and not the fullcolModelparameter.For example you can rewrite the code above to set the next from
colNamesinstead ofnamepropertiy in the tooltip: