Is it possible to lock a column based on it’s id using jquery? I’ve seen different solutions, like header locking, and some can also lock the columns indexing from left. What I am trying to do is when I click the lock button, it will lock the column and won’t be moved when scrolled horizontally.
For example I click the lock on header 1, scrolled horizontally, then clicked lock on header 3. Header 1 and Header 3 should be adjacent to each other and shouldn’t move when scrolled horizontally.
Below is my code:
<div style="float: left; width: 75%; overflow-x: scroll;">
<table style="width: 200% !important;">
<tr>
<td id="lid_1" colspan="3">
<div style="margin-top: 3px;">
January 24, 2013
<button id="lid_1">Lock</button>
</div>
</td>
<td id="lid_2" colspan="3">
<div style="margin-top: 3px;">
January 25, 2013
<button id="lid_2">Lock</button>
</div>
</td>
<td id="lid_3" colspan="3">
<div style="margin-top: 3px;">
January 26, 2013
<button id="lid_3">Lock</button>
</div>
</td>
<td id="lid_4" colspan="3">
<div style="margin-top: 3px;">
January 27, 2013
<button id="lid_4">Lock</button>
</div>
</td>
<td id="lid_5" colspan="3">
<div style="margin-top: 3px;">
January 27, 2013
<button id="lid_5">Lock</button>
</div>
</td>
<td id="lid_6" colspan="3">
<div style="margin-top: 3px;">
January 28, 2013
<button id="lid_6">Lock</button>
</div>
</td>
</tr>
<tr>
<td id="lid_1">Header 1</td>
<td id="lid_1">Header 2</td>
<td id="lid_1">Header 3</td>
<td id="lid_2">Header 1</td>
<td id="lid_2">Header 2</td>
<td id="lid_2">Header 3</td>
<td id="lid_3">Header 1</td>
<td id="lid_3">Header 2</td>
<td id="lid_3">Header 3</td>
<td id="lid_4">Header 1</td>
<td id="lid_4">Header 2</td>
<td id="lid_4">Header 3</td>
<td id="lid_5">Header 1</td>
<td id="lid_5">Header 2</td>
<td id="lid_5">Header 3</td>
<td id="lid_6">Header 1</td>
<td id="lid_6">Header 2</td>
<td id="lid_6">Header 3</td>
</tr>
<tr>
<td id="lid_1" colspan="3">
<table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<br/>
</table>
</td>
<td id="lid_2" colspan="3">
<table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<br/>
</table>
</td>
<td id="lid_3" colspan="3">
<table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<br/>
</table>
</td>
<td id="lid_4" colspan="3">
<table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<br/>
</table>
</td>
<td id="lid_5" colspan="3">
<table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<br/>
</table>
</td>
<td id="lid_6" colspan="3">
<table style="width:100.1%; margin-top: -17px !important; margin-left: -1px !important;">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<br/>
</table>
</td>
</tr>
</table>
OK, here’s a solution to your update.
However ids are meant to be unique so you shouldn’t have 2 or more same ids. Classes are the tool in general use-cases.
You may add unique ids if unique columns are required but not using them as reference in the context of locking, but extract the id when you want to do something with it.
Here are the examples:
http://jsbin.com/odaxil/5
http://jsbin.com/odaxil/5/edit
js:
HTML:
CSS: