Billable Hours Joke
A plumber attended to a leaking faucet at a neurosugeon's house. After a 2-minute job, he demanded $75.
"I don't charge this amount even though I'm a surgeon."
"You're right -- that's why I switched from surgery to plumbing!"
Entire Cell Clickable For Column Sort - ASP.NET
The one thing I love about datagrids is how easy you can make them sort your information. The thing I hate about the sort is you need to click the link to do it instead of the whole header cell. So I wrote up a little JavaScript function that makes the whole cell clickable for the sort! The following code needs to be placed between the head tags.
<script type="text/javascript">
//Code Makes Entire Headers Clickable For Sorting
function MakeHeadersClickable(xDataGridName){
var theLinks = document.getElementById(xDataGridName).getElementsByTagName("a");
//Grab all of the link elements
var numLinks = parseInt(theLinks.length);
for(i=0;i<numLinks;i++){ //Loop through the links
theFunc = theLinks[i].href.split("pt:"); //Determine the post back code and remove the javascript: text
if(theFunc.length > 1){
theLinks[i].offsetParent.onclick = new Function(theFunc[1]); //Add the onclick event to the header
//theLinks[i].className = "noUnde"; //Add CSS class to the link!
theLinks[i].offsetParent.style.cursor = "pointer"; //Add Css pointer(hand) cursor to the header cell
}
}
</script>
You just need to call the code by adding an onload event handler to your body tag with the parameter of your datagrids name
<body onload="MakeHeadersClickable('DataGrid1')">
Now when the page loads, the whole header column is made clickable! It is rather easy to do. If there is a way to do it without JavaScript someone please tell me.
Who is going to be the first Java person to complain about posting .NET stuff? LOL
Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages
TrackBacks[0]
Comments[2]
Posted by pascarello on December 17, 2004 9:43:45 AM EST
Reply |
Permalink
Re: Entire Cell Clickable For Column Sort - ASP.NET
I added a post about making entore rows and cells clickable with JavaScript since many people seem to be coming here from google!
link: Clickable Table Cells and Rows - JavaScript
Comment from Eric Pascarello on December 30, 2004 10:11:13 AM EST
Hi,
Thanks a lot for the gr8 idea...
It helped me out ...
Keep posting interesting thinks
Thanking u,
Mitra
Comment from Anonymous on May 23, 2005 12:20:57 AM EST
TrackBack to http://radio.javaranch.com/pascarello/addTrackBack.action?entry=1103294625000