Knowledgebase
Commenting the cells in the grid
Posted by Ivan Pashkov on 21 July 2013 02:07 PM

This article concerns only HierCube VCL


Very often the cells in the grid need to be commented. This can be helpful if you want to save your thoughts about the value of some grid cell and later use it by yourself or share it. The comments may be very useful to mark particular cells in the multidimensional cube. You can comment some cells and then easily find them on another cube slice or on another pivot state. The fact that the comments are saved in the steam along with the rest of the current grid state allows very easily distributing your comments on particular grid values between your colleagues. This article explains how the cells can be commented.

General information about the comments

A comment is a simple string that can be connected with some cells in the grid. When a cell is commented and visible in the current grid view then it is marked with a special symbol so that the user can notice it. Also the comment of the cell might appear as a hint when the user hovers the mouse over the commented cell. Thus it is very easy to share the comments between the users of the OLAP report.

There are two types of the cells that can be marked with the comments: data cells (the scrollable cells located in the data area of the grid) and dimension member cells a.k.a. "label nodes". The cells in the grid are identified and treated in the terms of data analysis of the multidimensional cube having in mind that the grid can be rotated, filtered, the data can be drilled down or up, etc. So if the cell with some value is commented it will still be commented in another view of the grid even if the cell is located in a different place of the grid. Actually the commented cell may be hidden at all and when it gets visible again the comment will still be there.

When the grid state is saved to a file the comments are also saved along with the other grid-specific data, so when later the grid state is restored the comments are restored too. Of course this can be turned off if needed.

The user can place a comment in the cell using the context menu "Comment cell". This command shows the dialog window that allows changing the current value of the cell comment. Also there are run-time methods to read and write the cell comments from the code.

Commenting the data cells

The data cells are located in the data area of the grid (the scrollable cells that display the numeric summary values). It is important to understand that the grid only displays a two-dimensional slice of the whole multidimensional cube.  In other words a user only interacts with the projection of the cube to the two-dimensional surface of the grid. When you put a comment into a data cell it is actually associated with the cube cell, not with the grid cell. The parameters identifying the cube cell consist of its multidimensional address (that is the values of all dimension members from all dimensions the cube uses), summary, function, and sub-function that the cell displays. So this commented cell can actually be in any position in the grid or even not visible at all, but if it is visible in the current grid view it is marked with a special symbol so that the user can notice the commented cell. This is suitable for the purpose of the data analysis because helps perceive the given grid as some part or slice of the cube. In the following two pictures the commented cell is considered the same in terms of the multidimensional cube. So it holds the same "Sales" value and the same comment.

Picture 1

Picture 2

Use the following property to read or write the comments of the data cells from within the code:

property THierCubeGrid.DataCellComment[ADataRow, ADataCol: integer]: WideString;

Commenting the dimension member cells

The dimension member cells are located in a fixed grid area (row or column) and display the dimension members. Every cell of this type is represented by the TLabelNode structure in the code. When you put a comment to such a cell, the comment is associated with this dimension member and all dimension members (probably from different dimensions) that are opened before it in the current grid view. In other words, the comment is associated with the chain of all open dimension members starting from the very first dimension in the area. For example, if the row area contains three dimensions: Products, Shippers, and OrderDate then the chain of the open dimension members may look like this: "Products.Dairy Products" -> "Shippers.Speedy Express" -> "OrderDate.1997" (see the picture below).

Picture 3

Here the commented cell is "1997" but in fact the comment will only be displayed if all dimension members in the chain are visible: "Dairy Products -> Speedy Express -> 1997". This chain may be located in another grid area, but it must hold all the members in it open and exactly in this given order. For example in the picture below the chain is moved to the column grid area, but remains unchanged, so the cell "1997" is still commented.

Picture 4

Use the following property to read or write the comments of the data cells from within the code:

property LabelNodeComment[LabelNode: TLabelNode]: WideString;

Code examples

1. This code sets the comment for the current data cell in the grid.

  with Grid do
    DataCellComment[DataRow, DataCol] := 'Comment text';

 

2. The following code explores through every data cell in the grid and sets the comment for everyone.

var
  ARow, ACol: integer;
begin
  Grid.GridInfo.BeginChange;
  with Grid do
  try
    for ARow := 0 to RowCount - FixedRows - 1 do
    for ACol := 0 to ColCount - FixedCols - 1 do
    DataCellComment[ARow, ACol] := Format('Row = %d, Col = %d', [ARow, ACol]);
  finally
    GridInfo.EndChange(geCellCommentChanged);
  end;
end;

 

3. The following code comments the most aggregated cell in the cube, i.e. the cell that contains the sum of the values of all cube cells (that is actually the sum of the summary values from all the records in the fact table). After that it marks the dimension members which the data cell belongs to.

var
  RowLabelNode, ColLabelNode: TLabelNode;
  SumInfo: TSummaryInfo;
begin
  with Grid do
  begin
    {+ Locate the subtotal nodes (the ones with the "Total" caption) in the row and column areas.
       The subtotal nodes in both row and column areas will result in the most aggregated cell of the cube }
    if GridInfo.RowLabelNodes <> nil then RowLabelNode := GridInfo.RowLabelNodes.FindSubTotal else RowLabelNode := nil;
    if GridInfo.ColLabelNodes <> nil then ColLabelNode := GridInfo.ColLabelNodes.FindSubTotal else ColLabelNode := nil;
    {+ Search for the summary named "Sales" }
    SumInfo := SummarySettings.FindDisplayName('Sales');
    {+ If no such summary found then just take the very first from the collection }
    if SumInfo = nil then SumInfo := SummarySettings[0];
    {+ Set the comment for the cube cell displaying the value of the Sum function }
    SetDataCellComment(RowLabelNode, ColLabelNode, SumInfo.ID, stSum, sstValue, 'Comment text');
    {+ Also mark the dimension captions (if there is any) that the data cell belongs to }
    LabelNodeComment[RowLabelNode] := 'This is a row subtotal';
    LabelNodeComment[ColLabelNode] := 'This is a column subtotal';
  end;
end;
(3 vote(s))
This article was helpful
This article was not helpful

Help Desk Software by Kayako Resolve