Frozen table header inside scrollable div

前端 未结 11 2118
Happy的楠姐
Happy的楠姐 2020-11-30 04:15

I\'ve three divs. Header, central and footer. There is a table in central div (gridview) which is almost always longer than outer div. So I\'ve made this div scrollable vert

11条回答
  •  -上瘾入骨i
    2020-11-30 05:05

    I've just put together a jQuery plugin that does exactly what you want. Its very small in size and really easy to implement.

    All that is required is a table that has a thead and tbody.

    You can wrap that table in a DIV with a classname and the table will always resize to fit in that div. so for example if your div scales with the browser window so will the table. The header will be fixed when scrolling. The footer will be fixed (if you enable a footer). You also have the option to clone the header in the footer and have it fixed. Also if you make your browser window too small and all columns can't fit...it will also scroll horizontally (header too).

    you just pass the DIV's classname to the plugin like so: $('.myDiv').fixedHeaderTable({footer: true, footerId: 'myFooterId'}); and the plugin will do the rest. FooterID is a element on the page that contains the mark-up for your footer. this is used if you want to have pagination as your footer.

    If you have multiple tables on the page it will also work for each table you want to have a fixed header.

    check it out here: http://fixedheadertable.mmalek.com/

    Keep in mind its still 'beta' so I am adding new features and bug fixes daily.

    Supported browsers: IE6, IE7, IE8, FireFox, Safari, and Chrome

提交回复
热议问题