将链接添加到jQgrid并在新窗口中打开 [英] Adding links to jQgrid and open in new window
问题描述
我有这个jqgrid定义,我正在尝试在新窗口中打开选定的文档.
I have this jqgrid definition and I'm trying to open the selected document in a new Window.
我的最终到达网址应为:
My final urls should like these:
http://localhost/XPagesSortableSearchResults.nsf/xPerson.xsp?documentId=9D93E80306A7AA88802572580072717A&action=openDocument
而且我还需要生成这种类型的网址:
and also I need to generate this type of url:
http://localhost/XPagesSortableSearchResults.nsf/$$OpenDominoDocument.xsp?documentId=9D93E80306A7AA88802572580072717&action=openDocument
$().ready(function(){
jQuery("#list2").jqGrid({
url:'./xGrid7.xsp/peoplejson',
datatype: "json",
colNames:['InternetAddress','#','Name','OfficeCountry'],
colModel:[
{name:'InternetAddress',index:'InternetAddress', width:200},
{name:'@position',index:'@position', width:50,sorttype:'int'},
{name:'$17',index:'$17', width:200},
{name:'OfficeCountry',
width:200,
formatter:editLinkFmatter
// formatter:'showlink',
// formatoptions:{ baseLinkUrl:'xPerson.xsp',addParam: '&action=openDocument', idName:'documentId'}
}
],
jsonReader: {
repeatitems: false,
id: '@unid',
root: function (obj) {
if ($.isArray(obj)) {
return obj;
}
if ($.isArray(obj.items)) {
return obj.items;
}
return [];
},
page: function () { return 1; },
total: function () { return 1; },
records: function (obj) {
if ($.isArray(obj)) {
return obj.length;
}
if ($.isArray(obj.items)) {
return obj.items.length;
}
return 0;
}
},
caption: "JSON Example",
height: 500,
gridview: true,
loadonce: true,
ignoreCase: true,
rowNum: 50,
rowList: [50, 100, 500, 1000],
pager: '#pager2'
}).jqGrid('filterToolbar', {stringResult: true, defaultSearch: 'cn', searchOnEnter: false});
请注意,我的Json对象看起来像这样,并且我没有在URL上使用我需要的documentId作为ColModel的一部分;我需要的值是@unid
Note my Json object looks like this and I'm not using the documentId I need on my url as part of my ColModel; the value I need is @unid
[
{
"@entryid":"1-B933790B1DC265ED8025725800728CC5",
"@unid":"B933790B1DC265ED8025725800728CC5",
"@noteid":"1E76E",
"@position":"1",
"@read":true,
"@siblings":40000,
"@form":"Person",
"$17":"Aaron, Adam",
"InternetAddress":"consurgo@compleo.net",
"OfficeCountry":"Namibia"
},
{
"@entryid":"2-9D93E80306A7AA88802572580072717A",
"@unid":"9D93E80306A7AA88802572580072717A",
"@noteid":"19376",
"@position":"2",
"@read":true,
"@siblings":40000,
"@form":"Person",
"$17":"Aaron, Dave",
"InternetAddress":"gratia@incito.co.uk",
"OfficeCountry":"Brazil"
},
{
"@entryid":"3-FAFA753960DB587A80257258007287CF",
"@unid":"FAFA753960DB587A80257258007287CF",
"@noteid":"1D842",
"@position":"3",
"@read":true,
"@siblings":40000,
"@form":"Person",
"$17":"Aaron, Donnie",
"InternetAddress":"vociferor@nequities.net",
"OfficeCountry":"Algeria"
}
]
到目前为止,我可以使用:
So far I make it work using:
{name:'OfficeCountry',
width:200,
formatter:'showlink',
formatoptions:{ baseLinkUrl:'xPerson.xsp',addParam: '&action=openDocument', idName:'documentId'}
}
但是我需要在新窗口中打开
but I need to open it in a new window
我还尝试了formatter:editLinkFmatter
I also tried with formatter:editLinkFmatter
function editLinkFmatter(cellvalue, options, rowObject) {
return "<a href='./" + rowObject[2] + "' class='requestlink'>" + cellvalue + "</a>";
//return "<a href='./documentId=" + rowObject.@unid + "' >Click here</a>";
//return "<a href='./documentId=" + options.idName + "&action=OpenDocument'>" + cellvalue + "</a>";
}
并且我不能使用rowObject.@ unid,因为节点名称
and I can't use rowObject.@unid because the node name
推荐答案
在我看来,您应该只在<a>
中使用target="_blank"
属性(请参阅此处).标准的"showlink"格式化程序支持target
属性.
It seems to me that you should just use target="_blank"
attribute in the <a>
(see here and here). The standard 'showlink' formatter supports target
attribute.
作为自定义格式化程序的替代方法,您可以使用'dynamicLink'格式化程序(请参见答案).您可以从此处下载最新版本的jQuery.jqGrid.dynamicLink.js
.
As the alternative to the custom formatter you can use 'dynamicLink' formatter (see the answer). You can download the last version of jQuery.jqGrid.dynamicLink.js
from here.
已更新:要评估名称为@unid
的属性,可以使用语法rowObject["@unid"]
.所以editLinkFmatter
可以像
UPDATED: To assess the property with the name @unid
you can use syntax rowObject["@unid"]
. So the editLinkFmatter
can be like
function editLinkFmatter(cellvalue, options, rowObject) {
return "<a href='?documentId=" + rowObject["@unid"] +
"&action=OpenDocument' class='requestlink'>" + cellvalue + "</a>";
}
或更像是
function editLinkFmatter(cellvalue, options, rowObject) {
return "<a href='?" +
$.param({
documentId: rowObject["@unid"],
action: 'OpenDocument'
}) + "' class='requestlink'>" + cellvalue + "</a>";
}
这篇关于将链接添加到jQgrid并在新窗口中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!