how do I create an HTML table with fixed/frozen left column and scrollable body?


How do I create an HTML table with fixed/frozen left column and scrollable body?



I need a simple solution. I know it's similar to some other questions, like:



But I need just a single left column to be frozen and I would prefer a simple and script-less solution.



If you want a table where only the columns scroll horizontally, you can position: absolute the first column (and specify its width explicitly), and then wrap the entire table in an overflow-x: scroll block. Don't bother trying this in IE7, however...



Relevant HTML & CSS:





Fiddle



This is an interesting jQuery plugin that creates fixed headers and/or columns.
Toggle fixed column to be true on the demo page to see it in action.



In case of fixed width left column the best solution is provided by Eamon Nerbonne.



In case of variable width left column the best solution I found is to make two identical tables and push one above another. Demo: http://jsfiddle.net/xG5QH/6/.



FWIW, here is a table that is scrollable with the head and side fixed.



http://codepen.io/ajkochanowicz/pen/KHdih



A little late but I did run across this thread when trying out solutions for myself. Assuming you're using modern browsers nowadays, I came up with a solution using CSS calc() to help guarantee widths met up.





Hope this helps someone!



Style the left column with position: fixed. (You'll presumably want to use top and left styles to control where exactly it occurs.)



I took Earmon Nerbonne's answer and edited it to work with tables that fill the whole width.



http://jsfiddle.net/DYgD6/6/



The width of the fixed column still needs to be a set value though.



If you're in Webdevelopper hell and need to make this work for IE6, here's a sample code I used:



This will work probably ONLY for IE6, so use conditional comments for the CSS.



No need to add any plugin, CSS can do this job !!!



The idea is to make the position of all the first cells in each column absolute, and make width fixed. Ex:



This hides some parts of some columns under the first column, so add an empty second column (add second empty td) with width same as the first column.



I tested and this works in Chrome and Firefox.



Eamon Nerbonne, I changed some css in your code and it's better now(the scroll bar starts from the first row)



http://jsfiddle.net/At8L8/



I just add two line :



If you're developing something more complicated and want multiple columns to be fixed/stuck to the left, you'll probably need something like this.





Opera was buggy for all of the previous answers when I tested them on my mac.
If you scroll through the table the fixed column disappears after you pass the first unfixed column. I went ahead and wrote the code below. It works in all the browsers I have locally installed. I don't know how ie handles it though.



Just keep that in mind that if you intend to skip rows in one table and not the other or change the heights of the rows you might need to adjust this code.



Alternatively, style the tbody with a predetermined size (via height:20em, for example) and use overflow-y:scroll;



Then, you can have a huge tbody, which will scroll independently of the rest of the page.



Here is another modification of the most popular answer, but with handling of variable length of text in the first column labels:
http://jsfiddle.net/ozx56n41/



Basically, I'm using the second column for creating row height, like was mentioned. But my fiddle actually works unlike most mentioned above.



HTML:



CSS:





This can be easily done with the help of datatables. People who are new to data tables, please refer to https://datatables.net/ .Its a plugin and offers a lot of features.In the the code given, header is fixed,first 3 columns are fixed and several other features are also there.



In HTML5, you can use CSS style.transform.
However, i reccomend you "swipe between pages" turn off If you implement on Mac.



look at sample codePen





Add this in the head:



Javascript:






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

The Dalles, Oregon

眉山市

清晰法令