在 jqGrid 自定义格式化程序中访问行数据 [英] Access row data in jqGrid custom formatter

查看:12
本文介绍了在 jqGrid 自定义格式化程序中访问行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个数据类型为 json 的网格.

We have a grid with datatype json.

我们有以下自定义格式化程序:

We have the following custom formatter:

function opsFormatter (cellvalue, options, rowObject){
    '<a title=MA href=javascript:showDialog(' + rowObject[5] + ')>MA<a>' + '&nbsp;&nbsp;';
}

除了 rowObject[5] 是否有任何对象表示法,我们可以在其中指定实际的列名(帐户")?即:rowObject.account.

Instead of rowObject[5] is there any object notation where we can specify the actual column name ("account")? Ie: rowObject.account.

这是网格定义:

$("#grid-pos").jqGrid({
    colNames:['Product', 'Type','Expiry', 'Put Call', 'Strike', 'Account','Long','Short', 'Open Qty', 'LTD', 'Operations'],
    colModel :[
               {name:'product', index:'product', width:75, sortable:false},
               {name:'type', index:'type', width:50, align:'right', sortable:false},
               {name:'expiry', index:'expiry', width:60, align:'right',stype:'select', searchoptions:{dataUrl:'expiry_select.htm'}, sortable:false},
               {name:'putCall', index:'putCall', width:65, sortable:false},
               {name:'strike', index:'strike', sorttype: 'float', width:70, sortable:false},
               {name:'account', index:'account', width:70, sortable:false},
               {name:'long', index:'long', width:55, align:'right', sortable:false},
               {name:'short', index:'short', width:55, align:'right', sortable:false},
               {name: 'openQty', index:'openQty', width:80, align:'center', formatter:closeoutFormatter, sortable:false},
               {name:'LTD', index:'LTD', width:65, align:'right', sortable:false},
               {index:'operations', width:105, title:false, align: 'center', formatter:opsFormatter, sortable:false}
               ],
               pager: '#div-pos-pager',
               caption: 'Positions'
});  

??

推荐答案

对我来说,这似乎是绝对正确的行为.rowObject 参数的值是 object,其属性名称与 colModel 的name"属性中定义的名称相同.account 属性就是其中之一.我想误解来自 自定义格式化程序:

It seems for me absolute correct behavior. The value of the parameter rowObject is object having properties with the same names as defined in the 'name' property of the colModel. The property account is one from there. I suppose that the misunderstanding come from the following part of the documentation of the custom formatter:

rowObject - 是表示的行数据以数据类型确定的格式选项....如果我们有数据类型:json/jsonstring - rowObject 是数组,按规则提供来自 jsonReader

rowObject - is a row data represented in the format determined from datatype option. ... If we have datatype: json/jsonstring - the rowObject is array, provided according to the rules from jsonReader

array这个词可能会引起误解.在 JavaScript 中 rowObject.account 可以用作 rowObject["account"],但不能使用 rowObject[5] 来访问rowObjectaccount 属性.只是文档中没有明确的书面语句.如果您是母语为英语的人,您可以重新编写文本,以免产生误解.文档是 wiki,任何人都可以更改任何文本.

Probably the word array follows to misunderstanding. In JavaScript rowObject.account can be used as rowObject["account"], but one can't use rowObject[5] to access the account property of rowObject. It is just not clear written sentence in the documentation. If you are a native English speaker you can reformulate the text so that it will has no misunderstandings. The documentation is wiki and any person can change any text.

这篇关于在 jqGrid 自定义格式化程序中访问行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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