JqSuite PHP:获取列名或ID? [英] JqSuite PHP: get column name or id?
问题描述
如何在我的自定义中获取列信息(名称或ID)格式功能?
$grid->dataType = 'json';
$grid->setColModel();
我的自定义格式功能
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代码摘录(查看源代码):
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
}
}]
我尝试使用rowObject.columnName
,但是它不起作用!
I have tried to use rowObject.columnName
but it won't work!
注意:我没有使用loadonce: true
PS:如果需要更多详细信息,请告诉我.
PS: please let me know if more details are needed.
推荐答案
由于您使用数据的repeatitems: false
格式,因此网格的输入数据应为具有命名属性的项目,其名称与colModel
中的属性.因此,用作formatter
的formatPdfLink
函数将以与原始数据相同的简单格式获取第三个参数rowObject
.例如,可以使用rowObject.pdf_1
.要访问另一列,您应该只使用该列的colModel
属性中的name
属性值.
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.
已更新:如果您多次使用同一个自定义格式化程序,则可能需要访问当前列的属性. options
参数将在这里为您提供帮助.
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.
function formatPdfLink(cellValue, options, rowObject) {
return "<a href='" + cellValue +
"' title='" + options.colModel.name +
"' ><img src='../img/PDF_icon.png ' /></a> ";
}
参数options
包含属性rowId
,colModel
,gid
和pos
.自定义格式化程序内部的this
被初始化为网格的DOM,因此您可以使用例如$(this).jqGrid("getGridParam", "parameterName")
或仅使用this.p.parameterName
来访问jqGrid的其他选项.属性colModel
仅包含当前列的列定义,而不包含完整的colModel
参数.
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.
例如,您可以重写上面的代码以设置colNames
中的下一个代码,而不是工具提示中的name
属性:
For example you can rewrite the code above to set the next from colNames
instead of name
propertiy in the tooltip:
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> ";
}
这篇关于JqSuite PHP:获取列名或ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!