Online find a lot of ready-made. None of them turned out to be. I had to do it myself.
(function($) {$.fn.fixheader={init:function(obj) {varp =obj.parent (); //Binding EventsP.scroll (Internalscroll); //get the first row of a table varHead = Obj.children ("Thead tr Th:first"); if(!head | | head.length = = 0) { varBODY = Obj.children ("tbody") [0]; Head= $ (body.children[0].children[0]); } varHeadheight =head.height (); //Create a new layer varHeaddiv = $ ("<div></div>"). AppendTo (P); Headdiv.css ({"Width": p[0].scrollwidth,"Position": "Absolute", "Top": P.offset (). Top,"Display": "None", "Background-color": "#f5f5f5", "Height": Headheight}); //Clone first Row varTable = $ ("<table id= ' Tblfixheader ' ></table>"). AppendTo (Headdiv); $ (obj[0].attributes). each (function () { if( This. Name = = "id" | | This. Name = = "ID" | | This. Name = = "Id")return true; if( This. Value.indexof ("Background-color") >-1) {table.attr ( This. Name, This. Value.replace (NewREGEXP ("Background-color", "G"), "")); } Else{table.attr ( This. Name, This. Value); } }); Table.css ("Text-align", "center"). CSS ("Background-color",NULL); varTR = $ ("<tr></tr>"). appendTo (table); if(body) {$ (body.children[0]). Children (). each (function() { varTD = $ ("<td></td>"). AppendTo (TR); Td.css ({"width": $ ( This). Width (),"Font-size": $ ( This). CSS ("Font-size"), "Background-color": $ ( This). CSS ("Background-color"), "Font-weight": "Bold" }); Td.text ($ ( This). text ()); }); } //Scrolling Events functionInternalscroll () {vartop =Obj.scrolltop (); if(Top <= 100-headheight) {Headdiv.css ("Display", "" "); }Else{headdiv.css ("Display", "none"); } $("#btnTest"). Val (top + "" +head.height ()); } $ (window). Resize (function() {setTimeout (100, Doresize ()); }); functiondoresize () {headdiv.css ("Width", p[0].scrollwidth); varTBL = $ ("#tblFixHeader"); if(tbl && Tbl.length = = 1) { varline = Obj.children (). Get (0). children[0]; if(line) {varLine2 = Tbl.children (). Get (0). children[0]; if(line2) { for(vari = 0; i < line.children.length; i++) {$ (line2.children[i]). CSS ("Width", $ (line.children[i]). CSS ("width")); } } } } } } };}) (jQuery);
Easy to use, take it away.
Jquery Table Fixed Header