Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:12:06+00:00 2026-06-15T07:12:06+00:00

I am looking for scrollable table. It works fine when width is fixed but

  • 0

I am looking for scrollable table. It works fine when width is fixed but it doesn’t works while columns are created dynamically.

<table cellspacing="0" cellpadding="0" border="0" width="325">
  <tr>
    <td>
       <table cellspacing="0" cellpadding="1" border="1" width="300" >
         <tr>
            <th>col 1 heading</th>
            <th>col 2 heading</th>
         </tr>
       </table>
    </td>
  </tr>
  <tr>
    <td>
       <div style="width:325px; height:48px; overflow:auto;">
         <table cellspacing="0" cellpadding="1" border="1" width="300" >
           <tr>
             <td>col 1 data 1</td>
             <td>col 2 data 1</td>
           </tr>
           <tr>
             <td>col 1 data 2</td>
             <td>col 2 data 2</td>
           </tr>
           <tr>
             <td>col 1 data 3</td>
             <td>col 2 data 3</td>
           </tr>
         </table>  
       </div>
    </td>
  </tr>
</table>

I found it from here http://www.scientificpsychic.com/blogentries/html-and-css-scrolling-table-with-fixed-heading.html

See demo

http://jsfiddle.net/u8yyD/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:12:09+00:00Added an answer on June 15, 2026 at 7:12 am

    Actually it’s quite similar question that i answered.

    $(function(){
        $("table").stickyTableHeaders();
    });
    
    /*! Copyright (c) 2011 by Jonas Mosbech - https://github.com/jmosbech/StickyTableHeaders
        MIT license info: https://github.com/jmosbech/StickyTableHeaders/blob/master/license.txt */
    
    ;(function ($, window, undefined) {
        'use strict';
    
        var pluginName = 'stickyTableHeaders';
        var defaults = {
                fixedOffset: 0
            };
    
        function Plugin (el, options) {
            // To avoid scope issues, use 'base' instead of 'this'
            // to reference this class from internal events and functions.
            var base = this;
    
            // Access to jQuery and DOM versions of element
            base.$el = $(el);
            base.el = el;
    
            // Cache DOM refs for performance reasons
            base.$window = $(window);
            base.$clonedHeader = null;
            base.$originalHeader = null;
    
            // Keep track of state
            base.isCloneVisible = false;
            base.leftOffset = null;
            base.topOffset = null;
    
            base.init = function () {
                base.options = $.extend({}, defaults, options);
    
                base.$el.each(function () {
                    var $this = $(this);
    
                    // remove padding on <table> to fix issue #7
                    $this.css('padding', 0);
    
                    $this.wrap('<div class="divTableWithFloatingHeader"></div>');
    
                    base.$originalHeader = $('thead:first', this);
                    base.$clonedHeader = base.$originalHeader.clone();
    
                    base.$clonedHeader.addClass('tableFloatingHeader');
                    base.$clonedHeader.css({
                        'position': 'fixed',
                        'top': 0,
                        'z-index': 1, // #18: opacity bug
                        'display': 'none'
                    });
    
                    base.$originalHeader.addClass('tableFloatingHeaderOriginal');
    
                    base.$originalHeader.after(base.$clonedHeader);
    
                    // enabling support for jquery.tablesorter plugin
                    // forward clicks on clone to original
                    $('th', base.$clonedHeader).click(function (e) {
                        var index = $('th', base.$clonedHeader).index(this);
                        $('th', base.$originalHeader).eq(index).click();
                    });
                    $this.bind('sortEnd', base.updateWidth);
                });
    
                base.updateWidth();
                base.toggleHeaders();
    
                base.$window.scroll(base.toggleHeaders);
                base.$window.resize(base.toggleHeaders);
                base.$window.resize(base.updateWidth);
            };
    
            base.toggleHeaders = function () {
                base.$el.each(function () {
                    var $this = $(this);
    
                    var newTopOffset = isNaN(base.options.fixedOffset) ?
                        base.options.fixedOffset.height() : base.options.fixedOffset;
    
                    var offset = $this.offset();
                    var scrollTop = base.$window.scrollTop() + newTopOffset;
                    var scrollLeft = base.$window.scrollLeft();
    
                    if ((scrollTop > offset.top) && (scrollTop < offset.top + $this.height())) {
                        var newLeft = offset.left - scrollLeft;
                        if (base.isCloneVisible && (newLeft === base.leftOffset) && (newTopOffset === base.topOffset)) {
                            return;
                        }
    
                        base.$clonedHeader.css({
                            'top': newTopOffset,
                            'margin-top': 0,
                            'left': newLeft,
                            'display': 'block'
                        });
                        base.$originalHeader.css('visibility', 'hidden');
                        base.isCloneVisible = true;
                        base.leftOffset = newLeft;
                        base.topOffset = newTopOffset;
                    }
                    else if (base.isCloneVisible) {
                        base.$clonedHeader.css('display', 'none');
                        base.$originalHeader.css('visibility', 'visible');
                        base.isCloneVisible = false;
                    }
                });
            };
    
            base.updateWidth = function () {
                // Copy cell widths and classes from original header
                $('th', base.$clonedHeader).each(function (index) {
                    var $this = $(this);
                    var $origCell = $('th', base.$originalHeader).eq(index);
                    this.className = $origCell.attr('class') || '';
                    $this.css('width', $origCell.width());
                });
    
                // Copy row width from whole table
                base.$clonedHeader.css('width', base.$originalHeader.width());
            };
    
            // Run initializer
            base.init();
        }
    
        // A really lightweight plugin wrapper around the constructor,
        // preventing against multiple instantiations
        $.fn[pluginName] = function ( options ) {
            return this.each(function () {
                if (!$.data(this, 'plugin_' + pluginName)) {
                    $.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
                }
            });
        };
    
    })(jQuery, window);
    

    see reference link

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: HTML table with fixed headers? Looking for a solution to create a
I have a table which has many columns and lots of records. My user
I'm looking to create a flexible width/height page layout with no window scrollbars! Any
I'm looking for a way to create a scrollable DIV that does not wrap
I'm not looking for finished code but more of a place to start; I
I'm looking to create a GridView with the paging hidden, but paging still allowed.
I'm looking to add interactivity to an image but cannot see a way off
I have a scrollable div that contains a table with many rows (100+). I
I am using this Scrollable plugin , and am looking at how to remove
I'm basically trying to achieve the following scrollable layout and am looking for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.