添加到jQgrid的链接并在新窗口中打开

时间:2012-03-28 17:44:29

标签: json url jqgrid parameters xpages

我有这个jqgrid定义,我正在尝试在新窗口中打开所选文档。

我的最终网址应该是这样的:

http://localhost/XPagesSortableSearchResults.nsf/xPerson.xsp?documentId=9D93E80306A7AA88802572580072717A&action=openDocument

我还需要生成这种类型的网址:

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

        [
      {
          "@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"
      }
]

到目前为止,我使用了以下方法:

  {name:'OfficeCountry',
               width:200,                                      
               formatter:'showlink',
               formatoptions:{ baseLinkUrl:'xPerson.xsp',addParam: '&action=openDocument', idName:'documentId'}
    }

但我需要在新窗口中打开它

我也尝试过使用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因为节点名称

1 个答案:

答案 0 :(得分:3)

在我看来,您应该在target="_blank"中使用<a>属性(请参阅herehere)。标准的“showlink”格式化程序支持target属性。

作为自定义格式化程序的替代方法,您可以使用'dynamicLink'格式化程序(请参阅the answer)。您可以从here下载最新版本的jQuery.jqGrid.dynamicLink.js

更新:要评估名称为@unid的媒体资源,您可以使用语法rowObject["@unid"]。所以editLinkFmatter就像

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