Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-selectable columns in HTML table

I have a table with multiple columns. I want content of each column to be selected individually. When I start selecting first column, second, third ... are automatically getting selected. When I select one column I want make other columns non selectable.

I have tried applying following class on elements and it worked fine in FF.No matter where you start selection from, its never selectable.

.unselectable {
    user-select: none; /* CSS3 */
    -moz-user-select: none;
    -khtml-user-select: none;
}

For IE I have tried property called unselectable="on", In Internet Explorer, it is still selectable if the selection starts outside. I want to prevent selection of certain columns even selection starts from outside.

I have tried using onselectionstart and onmouseover but as the selection is starting outside of element these are not getting triggered.

Do I have any hope ?

Thanks in advance.

like image 219
Gopal Avatar asked Oct 02 '11 16:10

Gopal


People also ask

How do I make a column invisible in HTML table?

To hide a column entirely from view, meaning it will not be displayed in either the normal or details row, simply use the visible column option and set it to false . This example shows a table where the first column ID is completely hidden from view using the data-visible column attribute.

How do I select a specific column in a table in HTML?

In Mozilla Firefox, users may highlight only certain rows, columns, or cells of an HTML table by holding down the Ctrl on the keyboard and click each cell individually.

Can an HTML table have different columns in different rows?

Cells within HTML tables can span multiple rows and multiple columns. The cell default is one row and one column. However, with the ROWSPAN attribute a cell can span more than one row, and with the COLSPAN attribute a cell can span more than one column.

How do I restrict column width in HTML table?

Use the style attribute with the width or height properties to specify the size of a table, row or column.


2 Answers

I believe that for now there is no pure CSS solution.

It may sound weird, but you could clone the content of the column you want the user to select into a separate table that will be positioned: absolutely over the original column.

like image 122
Lapple Avatar answered Sep 22 '22 08:09

Lapple


Instead of reinventing the wheel... check out http://www.datatables.net/

This is a JQuery table plug-in that'll knock your socks off.

It looks like it is already doing what you would like to do and it is free.

like image 34
Robert Bolton Avatar answered Sep 22 '22 08:09

Robert Bolton