Problem:
Many times SharePoint List has huge amount of records (Number
of items) and it’s hard to scroll out the view. Also while scrolling the page
we cannot determine which information is from which column.
Solution:
By simple applying CSS we can achieve the Frozen Headers
like Excel Sheet. And for achieving the same we use JQuery.
Implementation:
1. Go to List View Page and Html Form Webpart on the same page.
2. Copy Following code in Html Form Webpart. Just replace the LISTID and VIEWID (Highlighted in yellow color).
<script type="text/javascript"
src="/Style
Library/jq.Smoothness/js/jquery-1.5.1.min.js"></script>
<style type="text/css">
<!--
.DataGridFixedHeader { position: relative; top: expression (this.offsetParent.scrollTop); background-color: gray;}
-->
</style>
<script type="text/javascript">
$(function(){
var $table = $("TABLE[ID^='{F1D2645C-4CC3-458C-BC93-CBCFECD12171}-{5AB46E0C-D38F-4FF2-BBE0-0D485CC351E9}']:first","#MSO_ContentTable");
<!--WRAP
TABLE IN SCROLL PANE-->
$table.wrap("<DIV style='OVERFLOW: auto; HEIGHT: "
+ (screen.height-400) + "px'></DIV>");
<!--FROZEN
HEADER ROW-->
$("TR.ms-viewheadertr:first",
$table).addClass("DataGridFixedHeader");
});
</script>
|
Note:
For IE8 and IE9 browsers, require change in CSS class .DataGridFixedHeader as follows.
position: absolute;
Output:
Hello I am trying to use this exact code, I mean i changed the table Id.
ReplyDeleteBut I am not able to freeze the header.
Can you please tell me what could be the issue?
-Kunjan
Hi,
ReplyDeleteAbove code was tested on SharePoint 2010 and worked perfectly.
You can do some Troubleshooting:
1. Check Table GUID .
2. Add this code in HTML form WebPart on List view page.
3. Keep HTML form WP at the bottom of the page.
4. Check JQuery file Reference link.
If this not working post your code, i will check and let you know.
This comment has been removed by the author.
ReplyDeleteI use Sharepoint 2010 and IE 9.0, but your solution doesn't work.
ReplyDeleteThe above part will be frozen, not the table header. What did I wrong?
Do I place this code in a CEWP or Do i have to use SharePoint Designer? I tried in a CEWP part and it does not seem to do anything?
ReplyDeleteHi Sveta/Julian,
ReplyDeleteHave you tried above mentioned Troubleshooting tips?
Don’t use CEWP; use HTML Form WP.
Hi Amit
ReplyDeletehow can i find the 'jquery-1.5.1.min.js' file to upload it into style library
Use SharePoint Designer to upload the file.
ReplyDeletecould u plz share the file jquery-1.5.1.min.js
DeleteCould you please share the file jquery-1.5.1.min.js and tell me where to upload it to please?
DeleteHi Amit,
ReplyDeleteI used it.Its not working.I can see the scroll down but it does not freeze the header. I have used all the troubleshooting tips as well. It will be great if you could help me.
Check 'ms-viewheadertr' class is present. if Yes, then provide error message that appare in browser status bar.
DeleteIf Not, you are applying this solution on MOSS which is not supported by this solution.
Hi Amit,
ReplyDeleteI used your solution.. but the header isn’t frozen. I’m using SP 2010 with IE 9. I think that the CSS Style “.DataGridFixedHeader“ does not working with IE9. Specially the “top: expression (this.offsetParent.scrollTop);“. The JQuery is working the header is using the CSS Class and appears gray…When I switch the browser to IE7, the header row is working as expected.
Do you have any hints for me?
Hi,try below css for IE9 browser.
ReplyDeleteFor Class > .DataGridFixedHeader
Change > position: relative; To > position: absolute;
Hi, I have tried the code and also the troubleshooting but still the top header isnt freezing (it's also not being coloured grey). I'm using SharePoint 2010 and IE8.
ReplyDeleteHow do I post my code here? i keep getting an error stating your HTML cannot be accepted. PHP, ASP and other server side scripting is not allowed
Amit, Thank you so much for this. The code worked for me but I have a follow up question. After I was able to freeze the header row, the header row now covers up the first few lines of the first row of data. Additionally, the header columns no longer align with the columns in my list. Have you heard of these issues? Any help is greatly appreciated!
ReplyDeleteErin
The code worked for me too but I also have the same question as above. After I was able to freeze the header row, the header row now covers up the first few lines of the first row of data. Additionally, the header columns no longer align with the columns in my list. Any help is greatly appreciated!
ReplyDeleteActually for freezing the headers we need to detach the header TR from the rendered view HTML.
ReplyDeleteAnd here is the solution for this problem, gets the width each column of first data row, and set this width to each column of header row using JQuery.
Can you please elaborate how to detach the header TR as well as how to fix the widths of columns?
DeleteI would appreciate if you could please provide the instructions on how to detach the header TR. Could you please email me to radhisoms@gmail.com
DeleteAlso would like an elaboration on this. Thanks!
DeleteThanks for a wonderful post but I am greatly interested in knowing how to dettach the header TR and fixiing widths. Can you please elaborate and provide code for reference?
ReplyDeleteNeed to get this working urgently. Your help will be greatly appreciated.
Hi Amit, thanks for the great post but I am not getting the headers freeze, will you please suggest what should I do ?
ReplyDeleteI am applying this in publishing site with IE 10.
Hi Amit, Code is not working for me too..
ReplyDeleteWhat about SharePoint 2013? How can I accomplish that in 2013?
ReplyDeleteHello Everyone,
ReplyDeleteFirst of all good news is! I have implemented new jquery plug-in to freeze the list headers as well as columns. I will post it in few days. Just stabilizing it for all browsers and Office 365. No worries :)
And I apologies for inconvenience caused as I didn’t replied on few comments.
Figure crossed for new version…
Where is the new version?
DeleteHi Amit is the new version out yet?
ReplyDeleteIf someone could take a moment to help me make this code work. I have replaced the LIST and VIEW IDs, and changed the position to absolute. It is inserted into the HTML Form webpart. When I run through developer tools in IE11 (which is emulating IE8) there are no errors. I would very much appreciate any help.
ReplyDeleteHi, Is there any way to freeze the columns horizontally, so when I scroll to the right, the first 3 or 4 columns are frozen with the data
ReplyDelete