update to using tool tips in CFgrid
Tags: ColdFusion 8, Coldfusion
In a previous post that I wrote on this, which can be found at http://www.andyscott.id.au/2009/7/21/Have-you-ever-wanted-to-use-tooltips-in-cfgrid, I showed how to add tool tips to the CFgrid.
A user wanted to know how to get the information from the cell, and although you can see how he did it in the comments, I will not recommend doing it this way. The reason being is that in the future, you may start to apply formatting to the cell. Which would then make the method this user used, obsolete, but more importantly broken and looking at fixing the code.
So what is the best way to achieve what he wanted?
What most people don't know is that the Grid that is used by ColdFusion, actually has a datasource that holds all the information that is defined by setting the grid up. So in the example on the previous blog post, lets look at how this should be done correctly to then make the code not break if we make further modifications to it.
function mouseOver(e, tar){
var overCell = grid.getView().findCellIndex(t);
var overRow = grid.getView().findRowIndex(t);
var ds = grid.getDataSource();
}
Now as you can see we are getting the DataSource for the grid, and then it will be a matter of just getting the information that we need from the DataSource. So the above code will now look like the following.
function mouseOver(e, tar){
var overCell = grid.getView().findCellIndex(t);
var overRow = grid.getView().findRowIndex(t);
var ds = grid.getDataSource();
if(overCell !== false && overRow !== false) {
var cellData = ds.getAt(overRow).get('COLUMN');
}
}
It is important to note that the extra line where we are using getAt, I am using a custom CFGRid custom tag that uses UpperCase for the column names, so it is important to note that ColdFusion may be doing this with lowercase or uppercase as I can't recall off the top of my head.
Now this one line is basically saying that the row that we are currently over, we want to get the data from the cell named COLUMN, which is the name that you would have given it when defining the grid.
That is pretty much basically how it is done, this will work on ColdFusion 8 only, but in ColdFusion 9 you will need to change the getDataSource, to getSource() from memory, however you can see all these over at extjs.com and look at the API for the grid for future reference.
There are no comments for this entry.



TweetBacks