how to freeze vertical row in the HTML table

is it possible to freeze vertical row in the HTML table .

In my HTML table have 20 rows 30 column .

i want to freeze the 1the coulmn when i move to the horizontal scroll bar
LVL 20
Sathish David  Kumar NArchitectAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
I think this is a nice way from http://handsontable.com/demo/fixed.html.  I updated the code for keeping one column fixed and not the header http://jsfiddle.net/kjesyyx3/

HTML
<h2>Fixed rows and columns</h2>

<p>Specify two fixed rows with <code>fixedRowsTop: 2</code> and two fixed columns with <code>fixedColumnsLeft:
  2</code> option.</p>

<p>Note: You'll need horizontal scrollbars, so just set a container <code>width</code> and <code>overflow:
  scroll</code> in CSS.</p>

<pre id="positions">rowOffset: 81</pre>

<div id="example1" style="width: 400px; height: 300px; overflow: scroll" data-originalstyle="width: 400px; height: 300px; overflow: scroll" class="handsontable"></div>

<p>
  <button name="dump" data-instance="hot" data-dump="#example1" title="Prints current data source to Firebug/Chrome Dev Tools">
    Dump data to console
  </button>
</p>

Open in new window

JS  NOTE:  fixedColumnsLeft: 1,
$(document).ready(function () {

  /**
   * Container looks like this:
   *
   * <div id="example1" style="width: 400px; height: 300px; overflow: scroll"></div>
   */
  var myData = Handsontable.helper.createSpreadsheetData(1000, 100),
    container = document.getElementById('example1'),
    positions = document.getElementById('positions'),
    hot;
  
  hot = new Handsontable(container, {
    data: myData,
    colWidths: [65, 47, 47, 47, 47, 47, 47, 47, 47, 47],
    rowHeaders: true,
    colHeaders: true,
    fixedRowsTop: 0,
    fixedColumnsLeft: 1,
    contextMenu: true
  });
  
  setInterval(function () {
    var str = '';
  
    str += 'rowOffset: ' + hot.rowOffset();
  
    positions.innerHTML = str;
  }, 100);
  
  function bindDumpButton() {
  
      Handsontable.Dom.addEvent(document.body, 'click', function (e) {
  
        var element = e.target || e.srcElement;
  
        if (element.nodeName == "BUTTON" && element.name == 'dump') {
          var name = element.getAttribute('data-dump');
          var instance = element.getAttribute('data-instance');
          var hot = window[instance];
          console.log('data of ' + name, hot.getData());
        }
      });
    }
  bindDumpButton();

});

Open in new window

HTML
<h2>Fixed rows and columns</h2>

<p>Specify two fixed rows with <code>fixedRowsTop: 2</code> and two fixed columns with <code>fixedColumnsLeft:
  2</code> option.</p>

<p>Note: You'll need horizontal scrollbars, so just set a container <code>width</code> and <code>overflow:
  scroll</code> in CSS.</p>

<pre id="positions">rowOffset: 81</pre>

<div id="example1" style="width: 400px; height: 300px; overflow: scroll" data-originalstyle="width: 400px; height: 300px; overflow: scroll" class="handsontable"></div>

<p>
  <button name="dump" data-instance="hot" data-dump="#example1" title="Prints current data source to Firebug/Chrome Dev Tools">
    Dump data to console
  </button>
</p>

Open in new window

CSS
</style><!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ -->

<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>

<script src="http://handsontable.com/dist/handsontable.full.js"></script>
<link rel="stylesheet" media="screen" href="http://handsontable.com/dist/handsontable.full.css">
<link rel="stylesheet" media="screen" href="http://handsontable.com/demo/css/samples.css?20140331">
<link rel="stylesheet" media="screen" href="http://handsontable.com/demo/css/samples.css?20140331">
<link rel="stylesheet" media="screen" href="http://handsontable.com/demo/css/samples.css?20140331">

<style type="text/css">
body {background: white; margin: 20px;}
h2 {margin: 20px 0;}

Open in new window

Sathish David Kumar NArchitectAuthor Commented:
how can i do this for <div>Some Page Content </div>
    <table border=1>
            <thead>
                <tr>
                    <th>Head1</th>
                    <th>Head2</th>
                    <th>Head3</th>
                </tr>
            </thead>
    </table>
    <div style="max-height: 200px; overflow: auto;">
        <table id="test" border=1>
            <tbody>
                <tr> <td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td> </tr>
                <tr> <td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td> </tr>
                <tr> <td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td> </tr>
                <tr> <td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td> </tr>
                <tr> <td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td> </tr>
                <tr> <td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td> </tr> <tr> <td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td> </tr>
                <tr> <td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td> </tr>
                <tr> <td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td><td>content</td> <td>content</td> <td>content</td> </tr>
            </tbody>
        </table>
    </div>
<div>Some Page Content </div>
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
In that sample, the data is in object.  I updated the fiddle http://jsfiddle.net/ccu2b0o3/1/
var myData = data = [
      {id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
{id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
      {id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
      {id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
      {id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
  ],

Open in new window


$(document).ready(function () {

  /**
   * Container looks like this:
   *
   * <div id="example1" style="width: 400px; height: 300px; overflow: scroll"></div>
   */
  var myData = data = [
      {id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
{id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
      {id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
      {id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
      {id: 1, name: 'Ted', isActive: true, color: 'orange', date: '2008-01-01',content1: 'somethingelse',content2: 'test',content3:'abc', content4: 'dys', content5: 'ert'},
  ],
    container = document.getElementById('example1'),
    positions = document.getElementById('positions'),
    hot;
  
  hot = new Handsontable(container, {
    data: myData,
    colWidths: [65, 47, 47, 47, 47, 47, 47, 47, 47, 47],
    rowHeaders: true,
    colHeaders: true,
    fixedRowsTop: 0,
    fixedColumnsLeft: 1,
    contextMenu: true
  });
  
  setInterval(function () {
    var str = '';
  
    str += 'rowOffset: ' + hot.rowOffset();
  
    positions.innerHTML = str;
  }, 100);
  
  function bindDumpButton() {
  
      Handsontable.Dom.addEvent(document.body, 'click', function (e) {
  
        var element = e.target || e.srcElement;
  
        if (element.nodeName == "BUTTON" && element.name == 'dump') {
          var name = element.getAttribute('data-dump');
          var instance = element.getAttribute('data-instance');
          var hot = window[instance];
          console.log('data of ' + name, hot.getData());
        }
      });
    }
  bindDumpButton();

});

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.