Click here to Skip to main content
15,887,966 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I searched a lot in the internet and also applied the solutions but none of them worked for me actually. So, finally I am here and need your help.

Problem:
I have a blank asp.net grid and its getting populated using jquery ajax. I am specifying specific width for all the columns. I want the table header to be remain fixed while scrolling.

Now, I applied few css (as seen on internet):

CSS
#table_id thead, #table tbody
{
   display: block;
   width: 100%;
}


But, the whole table structure is getting messed up.

I also tried with plugins like "sticky table headers", "freeze headers", "datatable plugins" etc. but came with no luck.

Please give me some ideas to sort it out.

Thank you.
Posted

You can do this using pure CSS like:

CSS
table {
    border-spacing: 0;
    width:100%;
}
td + td {
    border-left:1px solid #eee;
}
td, th {
    border-bottom:1px solid #eee;
    background: #ddd;
    color: #000;
    padding: 10px 25px;
}
th {
    height: 0;
    line-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    color: transparent;
    border: none;
    white-space: nowrap;
}
th div {
    position: absolute;
    background: transparent;
    color: #fff;
    padding: 9px 25px;
    top: 0;
    margin-left: -25px;
    line-height: normal;
    border-left: 1px solid #800;
}
th:first-child div {
    border: none;
}


DEMO: FIDDLE[^]
 
Share this answer
 
I think you want to make the table boy scrollable. You can do it using CSS:
CSS
thead, tbody { display: block; }

tbody { 
    overflow-y: auto;    /* vertical scroll    */
    overflow-x: hidden; 
}

Fiddle[^]
-KR
 
Share this answer
 
As per my understand the post you are looking for scrollable gridview with fixed headers, If your requirement is that then refer below link here I explain you clearly how to achieve the above requirement with simple example http://www.dotnetspider.com/resources/45021-Scrollable-GridView-using-JQuery.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900