Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change column width irrespective of its content

I want to dynamically collapse table column to specific width (10 px in this case) whenever user clicks on column header. It will be good if we can keep the cells height fixed while changing the column width.
For example table will be displayed like:
enter image description here
When user clicks on column header (red minus button here), column should shrink and should look like:
enter image description here
Here in example given in jsFiddle column shrinks to fixed width and height remains same.

Here is what I have tried till now JsFiddle.

I have used:

  table-layout:fixed;
  word-wrap:break-word;    

but column shrinks to the width same as first word. It don't break the work to make width 10px.
Here column width shrinks to adapt word Lonnnnng.

It will be great if we get any plugin like datatable which allows this feature (i.e. dynamic collapse and expansion of columns to a particular width). There are many plugin which allows user to hide particular column but I want to shrink it instead of hiding.


EDIT :

After trying few suggestions I realize that a plugin will be better solution for this as I have to look after all browser and resolution supports.Doing all this stuff through written code will be the last thing I will do [I have to do :D ].Do we have any plugin which provides such feature?

like image 239
Ajinkya Avatar asked May 17 '12 10:05

Ajinkya


People also ask

How do I change the size of cells without changing the whole column?

Generally, every cell in a row or column has the same size, so you can't adjust the size of a cell individually without affecting the others in its same row or column. You can merge adjacent cells to create larger compound cells, however, and you can set rows and columns to automatically adjust to fit text.

How do I keep my column width fixed in HTML?

The width of the columns i.e. td in a table can be fixed very easily. This can be done by adding the width attribute in the <td> tag. If the width is not specified, the width of the column changes according to the change in the content. The specifications of width for the columns can be in pixels, or percentage.

How do I make table columns different width in HTML?

HTML tables can have different sizes for each column, row or the entire table. Use the style attribute with the width or height properties to specify the size of a table, row or column.

How do you change column width to fit the contents?

To change the width of columns to fit the contents, select the column or columns that you want to change, and then double-click the boundary to the right of a selected column heading. To change the width of all columns on the worksheet, click the Select All button, and then drag the boundary of any column heading.


1 Answers

Something like this: http://jsfiddle.net/jY7mb/1/

I wrapped the content of each cell in a div, and I adjust the width of the div instead of the width of the column.

like image 188
Tim Avatar answered Sep 20 '22 23:09

Tim