Question
· May 17, 2017

Need a trick to display cellTitle for just one column in tablePane

I need a trick to display the cellTitle for just ONE column in a tablePane with a unique value.  Here are the issues:

1. OnDrawCell has access to the cell data for that row/column, in %query(pName),  but setting the cellTitle property to a column doesn't refresh the column object

2. Setting showValueInTooltip is good for the entire table, not just one cell

3. ** the column element does not evaluate zen expressions, so I can't say cellTitle="#(%query.Comment)#", for example.  That's the crux of the problem.

<tablePane id="tblComplete"  
 tableName="MyTable" 
 orderByClause="ID DESC" 

#2 showValueInToolTip displays the tool tip for ALL cells

showValueInTooltip="true"        (Note: this shows the tool tip for EVERY cell)
<column colName="ID" colExpression="ID" hidden="true" />

<more columns here>

#3  - does not evaluate zen expression in <column> element; works with plain text though (cellTitle="Comment here")
<column colName="Comment" header="Comment"   OnDrawCell="onDrawCell" cellTitle="#(%query.Comment)#"  />  
</tablePane>

#1 OnDrawCell has access to the %query object, but not the column object.  This code doesn't set each cellTitle to the value for that cell in the row; just sets them all to the last value...

Method onDrawCell(pTable As %ZEN.Component.tablePane, pName As %String, pSeed As %String) As %Status
{
//Draw the comment column as an extract of the comment
if (pName = "Comment") {
set comment = ..EscapeHTML(%query(pName))
set line = $e(comment,1,49)
write line_" ..."

//this doesn't really work
set colCount = pTable.columns.Count()
set col = pTable.columns.GetAt(colCount)  //get last column, the Comment column
set col.cellTitle = %query(pName)
set ok = pTable.columns.SetAt(col,colCount)

}
quit $$$OK
}
 

Elsewhere I have access to the column objects (not the same as the value in each cell), but not the query values.

 I dont treally want to write out the whole table using html or by adding elements programattically, since the tablePane is so convenient for this situation.  

Goal:

ID column A    columnB    Comment

1  hi                    1/23/14          ... (tooltip = "Hello!")

2  no                   4/15/16          ... (tootip = "I entered a comment")

3  blah                 9/4/15           ... (tootip = "today I did something")

Thanks,

Laura

Discussion (2)1
Log in or sign up to continue

Hi Laura - not sure if you ever figured this  out, but here's an example using a generic OnDrawCell delegator method. The specific example is intended to run against a table in the SAMPLES namespace.

Class DC.Demo.CellTitle Extends %ZEN.Component.page
{

/// This XML block defines the contents of this page.
/// Setting XMLNamespace turns on StudioAssist for this XML block.
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen" ]
{
<page xmlns="http://www.intersystems.com/zen" height="100%">
<tablePane tableName="Sample.Company">
<column colName="ID" hidden="true" />
<column colName="Name" />
<column colName="Mission" OnDrawCell="DrawMissionCell" seed="90" />
</tablePane>
</page>
}

/// <var>pSeed</var> is the maximum length to show in the cell.
Method DrawMissionCell(pTable As %ZEN.Component.tablePane, pName As %String, pSeed As %String) As %Status
{
    Set tFullText = %query(pName)
    Set tTitle = ""
    Set tStyle = ""
    Set tLine = $Extract(tFullText,1,pSeed)
    If (tLine '= tFullText) {
        Set tStyle = "font-style: italic;"
        Set tTitle = tFullText
        Set tLine = tLine_" ..."
    }
    &html<<div style="#(tStyle)#" title="#(..EscapeHTML(tTitle))#">#(..EscapeHTML(tLine))#</div>>
    Quit $$$OK
}

}

An OnDrawCell delegator method generally just renders HTML for the table cell. In this case, if the text in the cell is greater than some specified length (the "seed" attribute of the column, which is passed to the OnDrawCell delegator method), then the text in the column is italicized and the tooltip is set to the full text. Otherwise, the cell is shown as usual with no tooltip. Note that the HTML escaping is done at the very end - you wouldn't want to truncate the text in the middle of an escape sequence.

You could make this method simpler and always have it show the tooltip, if you'd like. It's also generic (no hard-coded column name), so you could put it in a Zen template class and reuse it across multiple pages (probably after giving it a better name).

Another alternative would be subclassing %ZEN.Component.tablePane and overriding %DrawTable to add zen expression support to cellTitle, but unfortunately that method is quite ugly and monolithic. OnDrawCell is the most clear and maintainable option.

That's it!  Thank you!  You might have been thinking "it's so obvious", but I wasn't thinking of adding the attributes via html, just for that cell.  I was only thinking of "write", or using the column object to set its cellTitle property, which is not feasible since I can't get the column obejct.  But substituting html works great.  Thanks!

I was able to change the style just for cells whose columns are greater than pSeed (nice touch there), and I removed the showValueInToolTip for the rest of the cells.  I'm sure that would have been noticed at some point.

Laura