【问题标题】:Adding links to jQgrid and open in new window添加到 jQgrid 的链接并在新窗口中打开
【发布时间】:2012-04-12 08:44:14
【问题描述】:

我有这个 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 因为节点名称

【问题讨论】:

    标签: json url jqgrid parameters xpages


    【解决方案1】:

    在我看来,您应该只在&lt;a&gt; 中使用target="_blank"attribute(请参阅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>";
    }
    

    【讨论】:

    • 感谢@Oleg,我很清楚 _blank 属性;问题是我无法获得@unid 项目的行值。我尝试了 rowObject.@unid 并得到“无法将 AttributeName 转换为字符串”,因为我的项目名称上有 @;如果我尝试例如 rowObject.InternetAddress 工作正常。我也尝试了 rowObject[2] 没有任何乐趣,这就是为什么我使用 {name:'OfficeCountry', width:200, formatter:'showlink', formatoptions:{ baseLinkUrl:'xPerson.xsp',addParam: '&amp;action=openDocument', idName:'documentId'} } 并且工作正常但没有在新窗口中打开
    • @PSolano:哦!这不是一个真正的问题。您可以使用另一种语法:rowObject["@unid"]。您可以使用它,因为该属性有一些特殊字符,例如“@”或“”(空格),例如:rowObject["my property with spaces"]
    • 你绝对是男人。像魅力一样工作。我是一名 Notes 开发人员,我想在 Domino 应用程序上使用这个网格控件,但我还没有看到除了集成 jqGrid 和 Notes 之外的任何东西。还有很多问题,我进展缓慢,但进展良好。再次感谢。
    • @PSolano:不客气!我从未为 Domino 开发过(只为 Exchange 开发过一点点),但我知道它允许进行多种定制。如果你会成为更多的问题,我会尽力帮助你。最美好的祝愿!
    • 谢谢;如果您有时间看一下,我今天会发布一些问题。提前致谢
    猜你喜欢
    • 2015-02-09
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    • 2013-06-10
    • 2022-07-20
    • 2012-02-08
    • 1970-01-01
    相关资源
    最近更新 更多