Jquery Plugin-fixed table Header

Source: Internet
Author: User

Fixed table headers are a common topic. Many people have read their implementations from the Internet, but they are not satisfied. For many reasons, for example, the results are not implemented at all, or the ease of use is poor, so I tried to write a jquery Fixed Header plug-in and shared it with you. This plug-in is still in the test phase. If you want to use it directly, please fine-tune it according to your project.

Implementation principle:

 

Schematic description:

All rows (TR) can be divided into two parts: the table header and the table body. The table is split into two tables. The first table is the table header, and the second table is the table body, we need to drag the table body, so we will wrap the second table with a div for scroll, and then wrap it with a large Div, it looks like a complete table. In fact, the result is that two divs and two tables are assembled, and the original table is useless, if you delete it directly, it will be OK.

Jquery plug-in code:

// + Functions // | jquery Plugin: Fixed Header (test required) // | Author: Amin/+ ----------------------------------------------------- (function ($) {$. FN. extend ({scrolltable: function (options) {var defaults = {maxheight: 120, maxdataitemindex: 1 // pre-fixed maxdataitemindex as a Fixed Header}; Options = $. extend (defaults, options); return this. each (function () {var $ this = $ (this); // generate the header and body parts var $ clonetableheader = $ this. clone (); var $ clonetablebody = $ this. clone (); $ clonetableheader. find ("TR "). filter (function (INDEX) {return index> = options. maxdataitemindex }). remove (); $ clonetablebody. find ("TR "). filter (function (INDEX) {return index <options. maxdataitemindex }). remove (); // put the generated header and body part into the iner and make some fine-tuning $ this. after ("<Div class = 'scrolltableiner iner 'style = 'border: 1px solid;'> </div>"); $ this. next (). append ($ clonetableheader); $ this. next (). append ("<Div class = 'rolldiv 'style = 'overflow-Y: Scroll;'> </div>"); Define this.next().css ("width", $ this. width () + 20); $ this. next (). find ("Div. scrolldiv "mirror.css ({" Max-height ": options. maxheight, "width": $ this. width () + 20, "margin-top":-2}); $ this. next (). find ("Div. scrolldiv "). append ($ clonetablebody); $ this. remove () ;};}}) ;}( jquery );

  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.