How Do I Display Line Numbers in a Table?
This lesson will show you how to dynamically display line numbers in your data grid table.
Select the data grid and open the property inspector. Select the Columns pane (1) and add a column using the "+" button (2). Rename the column "Line Number" (3).
Use the up arrow (1) to move the Line Number column to the top of the list.
Create a template for this column by clicking on the "+" button at the bottom of the property inspector (2).
After creating the column template the card with the template group will open.
Now all that is left is to define the behavior for this column. Back in the Columns pane click the Column Behavior button (1) to open the script editor.
There isn't much to do here. In FillInData you just want to 'set the text of field 1 of me to the dgLine of me' (1). The dgLine is a property of a row template and this will display the line number for the current line. In LayoutControl you just need to set the rect of the field so that it fills the entire cell (2).
You may be wondering how you would set the dgText property of this data grid since we have added a "Line Number" column as the first column in the table.
When you set the dgText of a data grid you can pass a parameter specifying whether or not the first line of text contains the names of the columns that the data should map to. Just pass in true and prepend the column names to your data like this:
put "Name,Artist,Composer,Album" into theColNames set the dgText [true] of group "Data Grid" to theColNames & cr & theData