Master - detail grids

TreeGrid documentation

TreeGrid supports master / detail relationship as showing (master) row's children in different (detail) grid.
The detail grid can be shown outside the master grid, see External detail grids or inside the master grid, in some cell, see Nested detail grids.

The master grid contains all data and only master grid can upload changes to server.
Every master row (with Detail or DetailCol attribute) contains children that will be displayed in detail grid when the master row is chosen.

The detail children in master grid can be also created automatically by defining them as children of default row (<D>).
It is useful in creating master / detail relation for plain tables, where are the source data defined only once in the master root rows.

The detail grid contains only layout to define columns and fixed rows, but no variable data rows.
It is used to show and edit children of master row from master grid.
You can define data rows in detail grid to be displayed when it is empty - when does not display any master row's children.

It is possible to have completely different layout in detail grid than in master grid, use CopyTo attribute to provide correct relation between cells.

For classic master-detail relationship without tree you should specify MainCol='' and all master rows set Expanded='0'.
You can also use CopyTo attribute if you have editable cell in master row linked to cell in detail.

External detail grids

To define master / detail relationship, set <Cfg Detail='1' id='DetailGridId'/> in detail grid and <I Detail='DetailGridId'/> in master rows in master grid.
It is also possible to have a cascade of more related grids (detail grid can also be a master for another grid).
It is also possible to have one master grid with more detail grids or more master grids with one or more detail grids.

The way of master/detail relationship
The children (as in tree) of master row are displayed after focus/click/double click/expand in detail grid.
The children are still part of master grid's data and are downloaded / uploaded by master grid.
For the detail grid you need to specify the layout with empty data or with user row displayed when no data is shown in detail grid.
The layout of detail grid does not need to be the same as of master grid; you can add or hide other columns, but remember, uploading is done by master grid and only its columns are uploaded.
The rows can be dragged between master and detail grid.
One master grid can have more detail grids and one detail grid can have more master grids, but only one at a time.
The master and also detail grid can show data in tree, you can specify by Detail attribute which rows are shown as detail.

For more information see Master / detail tutorial.
upd 7.0 <I> string[ ]

Detail

Master row attribute
It is the main attribute for master / detail relationship in external grid.
Set it to id of detail grid where will be displayed the row's children. This means that every master row can be displayed in different detail grid.
Since 7.0 it can contain more ids, comma separated, to display the row's children in more detail grids.
<Cfg> bool

Detail

[0] Detail grid attribute
Set it to true for grid used as detail grid.
It is just support attribute to behave the detail grid slightly different - to not let users to add or drag rows into empty detail grid.
<Cfg> int

DetailOn

[1] Master grid attribute
Master grid attribute. When to show data in detail grid.
0 - disabled, 1 - on focus to row, 2 - on click to row, 3 - on double click to row.
For more options you can attach ShowDetail action to events like OnFocus, OnClickCel or OnDblClickCell.
<Cfg> int

DetailExpand

[0] Master grid attribute
What to do when expanding master row.
0 - show children in detail grid only
1 - expand the row only - the children will be visible only in master grid. The DetailOn should be 0 or 3.
2 - show children in detail grid and also expand the row - the children will be on two places in two copies and changes will be done to both.
<Actions>

ShowDetail ...F

Not attached to any event, master grid action
Shows data in detail grid for actual or focused row. It fails, if details grid already shows data for given row or the row is not master row.
This action is not attached to any event by default, because showing detail grid is controlled by DetailOn attribute.
<Actions>

RefreshDetail ...F

Not attached to any event, master grid action
Shows or refreshes data in detail grid for actual or focused row. It fails, if the row is not master row.
<Actions>

ClearDetail ...F

Not attached to any event, master grid action
Clears detail grid for actual or focused row. It fails, if the row is not master row.

Nested detail grids

It is possible to show the detail grid inside the master grid, in some cell of master row.
The master row should have set attribute DetailCol to the column name where to show the detail grid.

It is usually good to define the grid with <Cfg NoVScroll='1' NoHScroll='1'/> to always show the whole detail grid and avoid to have too many scrollbars.
To speed up the grid, it is good to define all columns in <Cols> section, to avoid a need of synchronizing row section heights. Define also <C Name='Panel'/> in the <Cols> to place panel here.
To correctly print the nested grid set PrintHeight of the detail row to the expected height of the nested grid.

For more information see Master / detail tutorial.
new 8.1 <I> string

DetailCol

Master row attribute
Name of column where (cell of the master row) to show the detail grid. All other cells in the master row will be normal cells with data.
This cell is usually spanned among other cells (see attribute Spanned and Span).
new 8.1 <I> string

DetailLayout

Master row attribute
Data source for downloading layout of the detail grid.
The detail grid data will be loaded from the master row children as usual for master / detail relationship.
It can be XML string, JSON string or URL. The URL cannot contain characters '<' and '{'.
The detail grid layout has predefined these default settings: <Cfg SuppressMessage='1' AbsoluteCursors='0' TabStop='0' NoVScroll='1' NestedGrid='1'/>
new 8.1 <I> string

DetailTreeGrid

Master row attribute
TreeGrid source tag of the detail grid. It should contain the <treegrid> / tag definition.
Useful to add some other setting to the detail grid.
For examples: DetailTreeGrid="<bdo Export_Url='Export.aspx' Export_Data='TGData' Export_Param_File='Test.xls'></bdo>" adds export settings to the detail grid.
new 8.1 API variable bool

NestedGrid

read only
Every nested detail grid has set this variable to 1.
new 9.3 API method void

RefreshNested

(TRow row)
Refreshes nested grid in given row. Use if the source data were changed.
Refreshes only already created nested grid.

Synchronizing grids

Especially nested detail grids can be synchronized, to share the same configuration and / or size.
new 8.1 upd 11.0 <Cfg> string[ ]

Sync

Detail grid attribute
What settings to synchronize among selected grids - among all grids with the same SyncId value.
Comma separated list of keywords, case insensitive.
All (substitution for Sort,Filter,Group,Search,Cols,Style), Sort, Filter, Group, Search, Cols (size, visibility and position),
Sec (new 9.3, width of column section, see more information), Horz (horizontal scroll), Horz0, Horz1, Horz2 (new 11.0, horizontal scroll of individual section, 0 left, 1 mid, 2 right), Vert (vertical scroll),
Style (new 9.0, CSS style), Zoom (new 9.3, Gantt zoom level and width)
All the grids should have the same columns to be synchronized successfully. All the grids should have the same Sync value to be synchronized in both ways.
For example if you change size of column 'X' in one grid, all the synchronized grids gets their column X resized to the same size.
Sync attribute can be used for not nested grids too.
new 8.1 <Cfg> string

SyncId

Detail grid attribute
Only grids with the same SyncId will be synchronized by Sync.
Also all grids with undefined SyncId will be synchronized together.
new 8.1 <Cfg> string

CfgId

Detail grid attribute
Under this name will be stored configuration to cookies.
Useful to set when more grids on page share the same configuration.
Set it the same for Sync='All', to let all the synchronized grids to use only one cookie.
Remember, all the grids should have the same layout to share their configuration.

Other settings for master / detail grids

new 7.0 <Cfg> string[ ]

MasterDef

Detail grid attribute
Comma separated list of default row names that can be displayed in this detail grid.
Only rows their Def attribute is listed in the MasterDef are displayed in this grid.
Useful when displaying one master row in more detail grids or displaying master / detail in tree with normal children.
new 13.0 <Cfg> string[ ]

MasterDefHide

Detail grid attribute
Comma separated list of default row names that will be hidden in this detail grid.
Useful when displaying detail grid also as master grid, in 3 or more levels of master / detail in tree with normal children.
new 7.0 <Cfg> int

DetailRowsVisible

[3] Detail grid attribute
If the rows that are hidden in master grid will be shown in detail grid. Does not affect deleted rows.
0 - never
1 - only rows hidden by filter
2 - all hidden rows
3 - all hidden rows and all the rows will get also CanFilter=1
new 7.0 <D> int

AddDefChildren

[1] Master grid attribute
When the child rows defined in default (the <D> <I/><I/>... </D>) will be added to all rows using the given default.
0 - only when adding new rows with the default
1 - also on start to all rows without children
2 - also on start to all rows. If the row has children, the new children will be added before them
3 - also on start to all rows. If the row has children, the new children will be added after them
<cell> string[ ]

CopyTo

Master cell attribute
List of cells where to copy this value after it is changed.
It is comma separated list: row1,col1,row2,col2,... row is row id, col is column name
row can also be these special words:
Parent - parent row, Next - next sibling, Prev - previous sibling, Children - all children
Children_X - All children with specified default as X
Child_X - specific child, if X is number, it means child on specified position (from 0), if X is string it means the first child with specified default (Def attribute).
Sibling_X - specific sibling, it is the same as Child_X, but relative to parent row and not to this row.
Used usually in master / detail relationship to copy (detail) children cells to master row cells and vice versa.
Cross references are permitted, because the copying is applied only if value is changed to different value.
upd 8.1 API event bool

OnShowDetail

(TGrid master, TGrid detail, TRow row, TRow old)
Called before master row's children are displayed in detail grid, can return true to suppress action.
(Since 8.1) the old is original master row showed in the detail grid, the row is new master row to show in the detail grid.
API event void

OnShowDetailFinish

(TGrid master, TGrid detail, TRow row)
Called after master row's children are displayed in detail grid.
upd 12.0 API method bool

ShowDetail

(TRow row, string detail_grid_id, bool test = 0)
Shows the master row's children in the given detail grid.
Returns true for success.
Since 12.0 if set test = 1, it does not change anything, just tests if it is possible.
API method void

RefreshDetail

(TGrid grid, bool clear)
Refreshes the given detail grid according to its actual master row's children.
If grid is null, refreshes all detail grids on page.
Refreshes only actually loaded detail grids - grids that have actually attached its master row.
If clear is true, clears the grid and removes the relation to the current master row.
new 8.1 API method TRow

GetMasterRow

( )
Detail grid method. Returns row from master grid that is actually shown in the detail grid or null.
new 11.0 API method TGrid

GetDetailGrid

(TRow row, int idx = 0)
Master grid method. Returns detail grid or nested grid shown for given master row.
If there are more grids shown for the row, the idx specifies the requested one.