I have written a cell formatter for a tree grid, which needs to access some ‘hidden’ data in the ListGridRecord:
private CellFormatter formatter = new CellFormatter() {
@Override
public String format(Object value, ListGridRecord record, int row, int col) {
String result = "";
if (value != null) {
String mimeType = record.getAttribute("type" + col);
String documentID = record.getAttribute("documentID" + col);
if (supportedMimeTypes.containsKey(mimeType)) {
if (mimeType.startsWith("image"))
result = "<img src=\"" + documentID + "\"alt=\"" + value.toString() +
"\" width=\"50%\" height=\"75%\">" + " ";
result += "<a href=\"" + documentID +
"\" target=\"_blank\">" + value.toString() + "</a>";
} else result = value.toString();
}
return result;
}
};
This works as expected as long as the user doesn’t hide columns via the header options because then the column my formatter gets does not correspond any more to the attribute id in the record.
How can I map the visible column number to the ‘real’ column number (similar to Swing’s JTable.convertColumnIndexToModel/convertColumnIndexToView).
I use GWT 2.0.3 and SmartGWT 2.1 on Vista Business x64
that is exactly what I do! If you look at my code you’ll see that I create the column names of my ‘hidden’ columns (type, documentID) exactly that way.
But since the column number that is passed to the formatter corresponds to the visible column number it changes, when you hide/show a column via the header menu. And then it does not correspond to the ‘real’ column number in my record anymore…
You’ve really lost me now. Since you don’t show the full data source and sample data I’ll make some assumptions.
Say you are showing these columns:
col1, col2, col3, col4
then you hide col3. The cell formatter firing for col=3 is for “col4”. Thus a call to getFieldName(col) should give you “col4”. So, stripping the # from the end of the field name gives you a recordColNum of “4”. Now you can grab “type4” and “documentID4” to format the cell. Is this not what you want?
If I’ve missed your request, please show more details on your data and what you see in your formatter for field name, etc.