Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
922 views
in Technique[技术] by (71.8m points)

jquery - Access row data in jqGrid custom formatter

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

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

This is the grid definition:

$("#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'
});  

??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 - 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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...