How to make some columns fixed and scrollable in a table?

I am designing a webpage using twitter-bootstrap 3 and some tables do not match my page margins. They are overflowing. So I want to create a structure that works like an Excel spreadsheet.

The leftmost two columns (blue area) will be fixed, and the columns will remain as possible. Overflow columns will be displayed if the user scrolls the scroll bar of the table to the right. You can see the picture as I want it.

enter image description here Putting a table in a div and a div rule overflow-x:scrollis not a solution for me. Because the first two columns must be visible all the time.

There is a solution here. I tried this. It only works when I reduce the window to a smaller width value.

+4
source share
6 answers

You can try the following:
Wrap your table in a div,
Absolute position of your first 2 columns, give them some width (say Apxu Bpx),
Use margin-left:(A+B)pxand overflow-x:scrollto wrap the div

Fiddle: http://jsfiddle.net/ycYdL/

+1
source

, jquery dataTable FixedColumns - , . jquery.dataTables.js jsfixedColumns.min.js( css ) CDN :

var table = $('#example').DataTable( {
  sScrollX: "100%",
  sScrollXInner: "150%",
  bScrollCollapse: true        
});
new $.fn.dataTable.FixedColumns(table);

. → http://jsfiddle.net/n2x8W/

dataTables , . CSS . , dataTables, , .. , / .

, 1.9.4, , 1.10.x.

+2

, . .

, , , "" . ( , ), , .

+1
0

div, , , div

0

, .,.

:

  • , (.. ).

  • div , . div overflow-x: scroll;.

, ( , ), .

, :

  • CSS ., , .
  • - (, ), " " , , .
0

Source: https://habr.com/ru/post/1539926/


All Articles