PeopleCode | Changing the label for a column in a grid
A. Field Label vs Grid Column Label
While our next task sounds simple enough – changing the label for a column in a grid – implanting the task occasionally causes some confusion. This is because setting a label for a grid column is not the same as setting a label for a normal page field.
Firstly, this is how you’d set a label for a normal page field:
RECORD_NAME.FIELD_NAME.Label = "New Label";
However, when the field is in a grid, you must instead use the object types of ‘Grid’ and ‘Grid Column’, setting the label property of the Grid Column:
Local Grid &grid = GetGrid(%Page, "GRID_NAME"); Local GridColumn &grid_col = &grid.GetColumn("PAGE_FIELD_NAME"); &grid_col.Label = "New Label";
B. Clarifying the Code
A couple of points about this code:
- Make sure to enter the name of your actual grid in the GRID_NAME field above. This can be determined by opening the properties of the Grid in App Designer and making a note of the ‘Page Field Name’ under the ‘General’ tab. This is normally, but not always, the same name as the primary record being used for the grid.
- Similarly, the grid column name (the ‘PAGE_FIELD_NAME’ in the example above) is determined by going into the properties of the grid column and noting the ‘Page Field Name’ entered on the ‘General’ tab. If this field is blank, enter a unique name for the field. This doesn’t have to be the same as the field object name, but it does need to be unique for the entire page.
If you prefer to leave the grid column label blank, set the Grid Column Label property equal to a single space:
&grid_col.Label = " ";
If you want to set the label back to its default character, use the empty space character:
&grid_col.Label = "";
C. Labels in Bulk: LabelColumns
There is one other option for setting a label for a grid column. The ‘LabelColumns’ method allows you to set a series of grid column labels all in one go. According to PeopleBooks, this approach is much quicker than setting the labels individually. For the method to work, you must firstly create a two-dimensional array that contains all the field name/label combinations. Once the array is populated, you can then go ahead and call the ‘LabelColumns’ method, passing in the array as a parameter.
Here is an example of setting the labels for three columns in a grid – COL1, COL2 and COL3:
/* Define grid and two-dimensional array */ Local Grid &grid = GetGrid(%Page, "GRID_NAME"); Local array of array of string &labels = CreateArray(CreateArray("","")); /* Set grid columns */ &labels [1] = CreateArray("COL1", "Column 1 Label"); &labels [2] = CreateArray("COL2", "Column 2 Label"); &labels [3] = CreateArray("COL3", "Column 3 Label"); /* Set labels */ &grid.LabelColumns(&labels);