是否可以在 SharePoint 列表中“冻结窗格”?

问题描述 投票:0回答:1

我需要保留我的列标题,以便人们可以看到那里显示的数据,但我找不到是否可能,或者如何做到这一点。在列表中添加导航栏也很好。有什么建议吗?

谢谢,

sharepoint list listview
1个回答
0
投票

我最近遇到了类似的挑战,并编写了以下代码。该代码适用于 IE,但 Chrome 中的 freeze header 的宽度存在问题。

无论如何,希望对你有帮助。

<script type="text/javascript">
$(document).ready(function(){
  // Replace 'NameOfList' with the name of the SharePoint list
  var $header = $("table[summary^='NameOfList']:first > tbody > tr.ms-viewheadertr"); 
  var headertop = $header.offset().top;

  // Replace 'NameOfColumn' with the name of the column that you would like to freeze
  var $fzCol= $("tr.ms-viewheadertr th:contains('NameOfColumn')");

  // IE has iFrame, Chrome doesn't have, so the 'n-th' count of the column is different in IE than in Chrome 
  if( $fzCol.siblings().eq(0).children().eq(0).prop("tagName") == "IFRAME"){ var shift = 0} else { var shift = 1};
  var nfzCol=$fzCol.index()+shift;

  var $mcol=$("table[summary^='NameOfList'] > tbody > tr:not(.ms-viewheadertr) > td:nth-child("+nfzCol+")");
  var colleft=$mcol.eq(0).offset().left;

  $(window).scroll(function(){
    var windowtop = $('body').scrollTop();
    if( windowtop > headertop ){
      $header.css({"position":"absolute", "top":windowtop});
    } else {
      $header.css({"position":"static", "top":"0px"});
    }

    var windowleft = $('body').scrollLeft();
    if (windowleft > colleft ){
      $mcol.css({"position":"relative", "left": windowleft-colleft});
    } else {
      $mcol.css({"position":"static", "left":"0px"});
    }
  });
}

© www.soinside.com 2019 - 2024. All rights reserved.