JqSuite PHP:获取列名或id

JqSuite PHP: get column name or id?

本文关键字:id 获取 PHP JqSuite      更新时间:2023-09-26

如何在自定义格式函数中获取列信息(名称或ID)?

grid.php中的一些代码:

$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,但它不起作用!

注意:我没有使用loadonce: true

附言:如果需要更多的细节,请告诉我。

因为使用repeatitems: false格式的数据,所以网格的输入数据应该是具有命名属性的项,这些属性的名称与colModelname属性的值相同。因此,用作formatterformatPdfLink函数将以与原始数据相同的简单格式获得第三个参数rowObject。例如可以使用CCD_ 9。要访问另一列,只需使用colModel中用于该列的name属性的值。

更新:如果多次使用同一自定义格式化程序,则可能需要访问当前列的属性。options参数将在这里为您提供帮助。

function formatPdfLink(cellValue, options, rowObject) {
    return "<a href='" + cellValue +
        "' title='" + options.colModel.name +
        "' ><img src='../img/PDF_icon.png ' /></a> ";
}

参数options包含属性rowIdcolModelgidpos。自定义格式化程序内部的this被初始化为网格的DOM,因此您可以使用例如$(this).jqGrid("getGridParam", "parameterName")或仅使用this.p.parameterName来访问jqGrid的其他选项。属性colModel仅包含当前列的列定义,而不包含完整的colModel参数。

例如,您可以重写上面的代码,从工具提示中的colNames而不是name属性设置下一个:

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> ";
}