Difference between revisions of "CellOnClick"

(Tweak to get Release tag working)
(Locals)
Line 3: Line 3:
  
 
{{ReleaseBar}}
 
{{ReleaseBar}}
 
 
== CellOnClick( expr ) ==
 
== CellOnClick( expr ) ==
  
Line 10: Line 9:
 
Use this function when you want to enable do some custom action when a user double-clicks on a particular cell in a result table. This behaves similarly to having a [[Button]] inside a table.
 
Use this function when you want to enable do some custom action when a user double-clicks on a particular cell in a result table. This behaves similarly to having a [[Button]] inside a table.
  
=={{Release|5.2||Coordinates of the cell}}==
+
== CellOnClick in row or column header cells ==
 +
 
 +
If you want to respond to clicks in a row header cell or column header cell, as with any other cell format predicate, you'll need to use [[CellSpan]] and specify the index and «header». For example
 +
 
 +
:<code>[[CellSpan]]( PlantType, [[CellOnClick]]( DoClickOnPlant(Self), header:true ) )</code>
 +
 
 +
where <code>PlantType</code> is an index, and <code>DoClickOnPlant</code> is a [[UDF]] with one parameter.
 +
 
 +
== Coordinates of the cell ==
 +
{{Release||5.1|Prior to [[Analytica 5.2]], the expression «expr» does not have direct access to the coordinates of the cell that was clicked.}}
 
{{Release|5.2||''New to [[Analytica 5.2]]''
 
{{Release|5.2||''New to [[Analytica 5.2]]''
  
 
In some cases, you may want to know the coordinates of the cell that was clicked from within «expr». In most cases, the coordinate of the cell is the value of each index of the table at that cell. This is available within «expr» by simply referring to the index by name in a value context. For example, when <code>In1</code> is an index, the expression
 
In some cases, you may want to know the coordinates of the cell that was clicked from within «expr». In most cases, the coordinate of the cell is the value of each index of the table at that cell. This is available within «expr» by simply referring to the index by name in a value context. For example, when <code>In1</code> is an index, the expression
 
:<code>[[MsgBox]](In1)</code>
 
:<code>[[MsgBox]](In1)</code>
 +
would normally show an array of values. But from within «expr», <code>[[CellOnClick]]([[MsgBox]](In1))</code> would show the single index element from <code>In1</code> corresponding to the cell that was clicked. All indexes appearing in the table, whether horizontal or vertical indexes, or a slicer index with a single value selected, behaves in this fashion.
 +
}}
  
would show an array of values. But from within «expr», <code>[[CellOnClick]]([[MsgBox]](In1))</code> would show the single index element from <code>In1</code> corresponding to the cell that was clicked. All indexes appearing in the table, whether horizontal or vertical indexes, or a slicer index with a single value selected, behaves in this fashion.
+
== Local Variables ==
 +
{{Release||5.1|Local variables cannot be used inside «expr» prior to [[Analytica 5.2]]}}
 +
{{Release||5.2|''New to [[Analytica 5.2]]''
 +
From within «expr», you can make use of the pre-defined locals (<code>VertIndex</code>, <code>HorizIndex</code>,  <code>ViewMode</code>,  <code>ComparisonIndex</code>,  <code>VertIndexes</code>,  <code>HorizIndexes</code>,  and<code>SlicersSetToTotal</code>) that are also available from within the [[Cell Format Expression]] attribute. You can also use the value of any local you declared in your [[Cell Format Expression]] that was in lexical scope at the point were the [[CellOnClick]] predicate appears. And you can declare additional locals inside «expr».
 +
 
 +
The index-valued locals such as <code>HorizIndex</code>, <code>VertIndex</code> and <code>ComparisonIndex</code> contain either [[Null]] or a [[handle]] to the index. These are not aliases of the index, so you can use them as if they were the index identifier itself (they can't be aliases since there might not be a horizontal or vertical index, so they might be null). So if you refer to their value, it'll be of type handle. If you want the coordinate at the horizontal index in any pivot, use e.g.,
 +
 
 +
<code>[[Local]] hCoord {{eq}}  ([[If]] HorizIndex<>[[Null]] [[Then]] [[LocalAlias]] hVal {{eq}} HorizIndex Do hVal [[Else]] [[Null]]);</code>
 +
 
 +
Notice that the [[If]] protects against the case where there is no horizontal index in the table. The [[LocalAlias]] makes <code>hVal</code> equivalent to the index identifir, so by referring to its value you get the the coordinate of the clicked cell, as described in the previous section.  
 
}}
 
}}
 
== Examples ==
 
== Examples ==
Line 25: Line 44:
 
When the user clicks on any cell in the table, a message box shows the value at full precision.
 
When the user clicks on any cell in the table, a message box shows the value at full precision.
 
:<code>[[CellOnClick]]( [[MsgBox]]( [[NumberToText]]([[Self]],fullPrecision:true) ) )</code>
 
:<code>[[CellOnClick]]( [[MsgBox]]( [[NumberToText]]([[Self]],fullPrecision:true) ) )</code>
 +
 +
== History ==
 +
[[CellOnClick]] was introduced in [[Analytica 5.0]].
 +
 +
Access to local variables and the coordinate of the cell clicked from within the «expr» expression were added in [[Analytica 5.2]].
  
 
== See Also ==
 
== See Also ==
 
* [[Computed cell formats]]
 
* [[Computed cell formats]]
 
* [[:category:Cell format functions]]
 
* [[:category:Cell format functions]]

Revision as of 19:26, 22 September 2018




Release:

4.6  •  5.0  •  5.1  •  5.2  •  5.3  •  5.4  •  6.0  •  6.1  •  6.2  •  6.3  •  6.4  •  6.5  •  6.6


CellOnClick( expr )

A cell format predicate that specifies an expression to be evaluated when a user double-clicks on a table cell (for example in a result table). This can be configured from within a computed cell format in the Cell Format Expression attribute. The expression «expr» is allowed to have side-effects, such as assignments to global variables, in the same way an OnClick or OnChange expression can.

Use this function when you want to enable do some custom action when a user double-clicks on a particular cell in a result table. This behaves similarly to having a Button inside a table.

CellOnClick in row or column header cells

If you want to respond to clicks in a row header cell or column header cell, as with any other cell format predicate, you'll need to use CellSpan and specify the index and «header». For example

CellSpan( PlantType, CellOnClick( DoClickOnPlant(Self), header:true ) )

where PlantType is an index, and DoClickOnPlant is a UDF with one parameter.

Coordinates of the cell

New to Analytica 5.2

In some cases, you may want to know the coordinates of the cell that was clicked from within «expr». In most cases, the coordinate of the cell is the value of each index of the table at that cell. This is available within «expr» by simply referring to the index by name in a value context. For example, when In1 is an index, the expression

MsgBox(In1)

would normally show an array of values. But from within «expr», CellOnClick(MsgBox(In1)) would show the single index element from In1 corresponding to the cell that was clicked. All indexes appearing in the table, whether horizontal or vertical indexes, or a slicer index with a single value selected, behaves in this fashion.

Local Variables

Examples

With the following Cell Format Expression, when the user double-clicks on any cell in the I='b' row of the result table, the user interface will open the influence diagram for the module Mo1.

If I='b' Then CellOnClick( ShowWindow( Handle(Mo1), 'Diagram' ) )

When the user clicks on any cell in the table, a message box shows the value at full precision.

CellOnClick( MsgBox( NumberToText(Self,fullPrecision:true) ) )

History

CellOnClick was introduced in Analytica 5.0.

Access to local variables and the coordinate of the cell clicked from within the «expr» expression were added in Analytica 5.2.

See Also

Comments


You are not allowed to post comments.