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

时间:2009-07-27 17:15:39

标签: sharepoint list listview

我需要保留我的列标题,以便人们可以看到那里显示的数据,但我无法找到它是否可行,或者如何执行。也很高兴在列表中添加导航栏。有什么建议吗?

谢谢,

2 个答案:

答案 0 :(得分:1)

答案 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"});
    }
  });
}