Code Snippet: Freezing Datagrid Header/Columns Made Easy
First posted on 11/10/2004, Last Updated on 5/28/2005 by
Richard Xin
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
You have already known how to make you long datagrid scrollable, however, when you scroll the grid, the header of the datagrid scrolls away. To make scrollable datagrid more user friendly, you may want to "freeze" the header while scrolling, and sometimes you may need to "freeze" your columns like Excel Spreedsheet. There are some third party components around to help you to implement these, and I believe those components used javascript heavily, it will take lots of time to develop such component if you decide to do it your own. My solution is pretty easy with only couple lines of code, the con is that it only works with IE 5 & up, becase I used CSS Expression which is used to assign a JavaScript expression to a CSS property, and it was first introduced in IE 5. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Freeze Header: 1. Define class .Freezing in Stylesheet:
3. You are done! Freeze Columns:
2. Assign Columns' cssClass to FreezingCol
3. You are done! Please keep in mind this solution only works with IE5 & up. To make cross browser solution, you need to use javascript which is out of scope of this article. Happy Programming! |
Freeze header of scrollable datagrid
最新推荐文章于 2024-09-03 09:24:05 发布