How Do I Override the Default Behavior For Rendering Data to a Cell?
By default, a data grid table uses a single field object for each cell in a table and assigns the text property of that field to the cell's data. This lesson will show you how to quickly create your own script that determines how data is rendered in the default table cell. This can be useful for rendering HTML and unicode text, trailing off text that is too wide for a column or for coloring particular cells.
Create a Button
Set the Script Of The Button
When creating your own default column behavior it is a good idea to start with the script that the data grid uses by default. You can copy the data grid default script easily enough by selecting the button (1) and executing the following statement in the Message Box (2):
set the script of selobj() to the script of button "Default Column" of stack "revDataGridLibrary"
Set 'default column behavior' Property
Example: Truncate Tail
As an example, I will show you how to truncate the tail end of every cell whose content is too wide to fit. The data grid provides a helper command named TruncateTail that takes the short id of a field and a string that signifies the text is being truncated. I've added a call to TruncateTail to the FillInData and LayoutControl handlers so that cell contents are truncated when drawn or when a column is resized.
Note: TruncateTail works fairly well for most cases but can cause visual lag if there are lots of cells being displayed that use TruncateTail. You should test your data and table to make sure it performs adequately for your needs.
Quick Tip: You can determine the name of the column that is being rendered by checking the dgColumn property. You could use this property if you only wanted to truncate the text in certain columns:
switch the dgColumn of me
case "Col 1"
case "Col 2"
TruncateTail the short id of me, "..."