JqSuite PHP:获取列名或ID? [英] JqSuite PHP: get column name or id?

查看:97
本文介绍了JqSuite PHP:获取列名或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中的属性.因此,用作formatterformatPdfLink函数将以与原始数据相同的简单格式获取第三个参数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包含属性rowIdcolModelgidpos.自定义格式化程序内部的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆