areyouready344
asked on
how to make column header fix in a jquery table using body column width?
how to make column header fix in a jquery table?
when I attempt to use the following CSS, the table stay fix but loses its width with tbody
table tr
{
position:fixed;
}
<title>Untitle</title>
<style type="text/css">
.chighlight
{
background-color:#408080;
color:white;
}
.scheckbox_column
{
width:48px;
height:20px;
}
.scolumn_a
{
width:198px;
height:20px;
overflow:hidden;
}
.scolumn_b
{
width:719px;
height:20px;
overflow:hidden;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery-1.1.3.1.pack.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery.dimensions.pack.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery.cookies.pack.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery.iutil.pack.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery.idrag.js"></script>
<script type="text/javascript" src="jquery.grid.columnSiz ing.js"></ script>
<script type="text/javascript">
$(function()
{
$("table").columnSizing()
$('input[type=checkbox]'). bind('clic k change',function(){
if( this.checked )
{
var row=$(this).closest('tr');
alert( row.attr('id'));
alert( $('td:eq(1)', row).html() )//second cell
alert( $('td:eq(2)', row).html() )//third cell
}
});
});
$(document).ready(function (){
$('.highlight').mouseover( function() {
l = $(this).parents("table").f ind("tr"). index( $(this) );
$('.chighlight').removeCla ss('chighl ight');
$(this).addClass('chighlig ht');
});
l = -1;
$(document).keyup(function (e) {
if(e.keyCode == 38) {
if(--l<0) {
l = 0;
}
$("tr","table").removeClas s('chighli ght');
$("tr:eq(" + l + ")","table").addClass('chi ghlight');
}
else if(e.keyCode == 40) {
if(++l>$("tr", "table").length-1) {
l = $("tr", "table").length-1;
}
$("tr","table").removeClas s('chighli ght');
$("tr:eq(" + l + ")","table").addClass('chi ghlight');
}
else if(e.keyCode == 32) {
$("input[type='checkbox'][ name='vehi cle']", "tr.chighlight").focus().c lick();
}
})
});
</script>
</head>
<body>
<div id="divTable" style="overflow-x:hidden; overflow-y:scroll;margin-l eft:auto;m argin-righ t:auto;mar gin-top:20 0px;height :300px;wid th:710px">
<table id="theTable" border='1' style="width:700px;height: 300px;">
<thead><tr><th class="checkbox_colum">Sel ection</th ><th class="column">Column A</th><th class="column">Column B</th></tr></thead>
<tbody>
<tr id='rowa' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowb' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowc' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowd' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowe' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowf' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowg' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowh' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowi' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowj' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowk' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowl' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowm' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rown' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowo' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowp' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowq' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowr' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rows' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowt' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowu' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowv' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='roww' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
<tr id='rowx' class="highlight"><td class="checkbox_column"><i nput type="checkbox" name="vehicle"/></td><td class="column_a">a</td><td class="column_b">b</td></t r>
</tbody>
</table>
</div>
</body>
</html>
when I attempt to use the following CSS, the table stay fix but loses its width with tbody
table tr
{
position:fixed;
}
<title>Untitle</title>
<style type="text/css">
.chighlight
{
background-color:#408080;
color:white;
}
.scheckbox_column
{
width:48px;
height:20px;
}
.scolumn_a
{
width:198px;
height:20px;
overflow:hidden;
}
.scolumn_b
{
width:719px;
height:20px;
overflow:hidden;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery-1.1.3.1.pack.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery.dimensions.pack.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery.cookies.pack.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery.iutil.pack.js"></script>
<script type="text/javascript" src="http://www.ita.es/jquery/jquery.idrag.js"></script>
<script type="text/javascript" src="jquery.grid.columnSiz
<script type="text/javascript">
$(function()
{
$("table").columnSizing()
$('input[type=checkbox]').
if( this.checked )
{
var row=$(this).closest('tr');
alert( row.attr('id'));
alert( $('td:eq(1)', row).html() )//second cell
alert( $('td:eq(2)', row).html() )//third cell
}
});
});
$(document).ready(function
$('.highlight').mouseover(
l = $(this).parents("table").f
$('.chighlight').removeCla
$(this).addClass('chighlig
});
l = -1;
$(document).keyup(function
if(e.keyCode == 38) {
if(--l<0) {
l = 0;
}
$("tr","table").removeClas
$("tr:eq(" + l + ")","table").addClass('chi
}
else if(e.keyCode == 40) {
if(++l>$("tr", "table").length-1) {
l = $("tr", "table").length-1;
}
$("tr","table").removeClas
$("tr:eq(" + l + ")","table").addClass('chi
}
else if(e.keyCode == 32) {
$("input[type='checkbox'][
}
})
});
</script>
</head>
<body>
<div id="divTable" style="overflow-x:hidden; overflow-y:scroll;margin-l
<table id="theTable" border='1' style="width:700px;height:
<thead><tr><th class="checkbox_colum">Sel
<tbody>
<tr id='rowa' class="highlight"><td class="checkbox_column"><i
<tr id='rowb' class="highlight"><td class="checkbox_column"><i
<tr id='rowc' class="highlight"><td class="checkbox_column"><i
<tr id='rowd' class="highlight"><td class="checkbox_column"><i
<tr id='rowe' class="highlight"><td class="checkbox_column"><i
<tr id='rowf' class="highlight"><td class="checkbox_column"><i
<tr id='rowg' class="highlight"><td class="checkbox_column"><i
<tr id='rowh' class="highlight"><td class="checkbox_column"><i
<tr id='rowi' class="highlight"><td class="checkbox_column"><i
<tr id='rowj' class="highlight"><td class="checkbox_column"><i
<tr id='rowk' class="highlight"><td class="checkbox_column"><i
<tr id='rowl' class="highlight"><td class="checkbox_column"><i
<tr id='rowm' class="highlight"><td class="checkbox_column"><i
<tr id='rown' class="highlight"><td class="checkbox_column"><i
<tr id='rowo' class="highlight"><td class="checkbox_column"><i
<tr id='rowp' class="highlight"><td class="checkbox_column"><i
<tr id='rowq' class="highlight"><td class="checkbox_column"><i
<tr id='rowr' class="highlight"><td class="checkbox_column"><i
<tr id='rows' class="highlight"><td class="checkbox_column"><i
<tr id='rowt' class="highlight"><td class="checkbox_column"><i
<tr id='rowu' class="highlight"><td class="checkbox_column"><i
<tr id='rowv' class="highlight"><td class="checkbox_column"><i
<tr id='roww' class="highlight"><td class="checkbox_column"><i
<tr id='rowx' class="highlight"><td class="checkbox_column"><i
</tbody>
</table>
</div>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER