Default rows

TreeGrid documentation

Every row <I> has predefined attribute values in its default row <D>. The values from <D> are used when the row <I> has some attribute not set. If row has attribute set to empty value, the default value is not used.
Using defaults helps you to reduce data size and also to control adding and moving rows. But using defaults is not required.
Using defaults is good especially for trees with different levels, at least to differentiate tree nodes and data rows.
Default rows are used for restrictions in dragging and copying rows in tree.

Defaults <D> are identified by their attribute Name. By this Name string are referenced from rows or other defaults by attributes Def or CDef.

Def attribute specifies default for the row itself.
You can use Def attribute even in <D> tag to reference one or more other <D>. This means that you define <I> that references to its <D> that references to another <D>, that ...
If you don't set Def attribute for any <D> or <I> tag the default is always <D Name="R">. Only for fixed rows is predefined <D Name="Fixed"> that references "R" default too. This means that any attribute value not set in branch of <I> and <D> tags is at last read from "R" default.
Pay attention to cross-references among <D> tags.

CDef attribute specifies default for all immediate children rows, but only if they have not set their own Def attribute.
When adding rows to children of the row, the new row will implicitly have default the same as parent rows' CDef.
You can use CDef attribute even in <D> tag to predefine CDef attribute for all rows that use this default (the CDef attribute does not concern <D> tag itself, unlike Def attribute).
The CDef attribute can be also set in tag <Root>, this specifies default for all root rows. In this case <Root> acts as parent for all variable root rows, including adding and dragging rows to root.

You can specify to row which default to use by many ways, all can be done in every case, but some are better for some cases and some for other cases.
Using Def attribute only is simpler but by CDef attribute you can control more. Remember, CDef attribute you can set even in <D> and <Root> tags too.

If you don't use any Def or CDef attributes, all variable rows will have default <D Name="R">, header rows <D Name="Header">, other fixed rows <D Name="Fixed"> and solid rows <D Name="Solid">. These <D> are defined in basic file Defaults.xml. It means, if you don't need to use defaults, you need not do it. You can change attributes of "R" or "Fixed" if you use <D> tag with this name in your data. New attributes you specify are merged or overwrite attributes specified in Defaults.xml => you don't need to edit this file for every new grid.

Example of default rows

This example show basic usage of default rows and Def and CDef attributes.

<Grid>
<Cols><C Name='A'/></Cols>
<Def>
<D Name='R' Expanded='0'/>
<D Name='Fixed' CanEdit='0'/>
<D Name='D1' AType='Int'/>
<D Name='D2' AType='Lines'/>
<D Name='D3' AcceptDef='D1,D3'/>
<D Name='D4' CDef='D3' Def='D2'/>
</Def>
<Root CDef='D4'/>
<Head>
<I/>
</Head>
<Body>
<B>
<I/>
<I Def='D1' CDef='D3'>
<I/>
</I>
</B>
</Body>
</Grid>



All rows in grid will be collapsed
All fixed rows in grid will be read only
This custom default sets type of column 'A' to integer
This custom default sets type of column 'A' to multiline text
This custom default permits dragging rows with Def='D1' and Def='D3' as children of rows that have Def='D3'
This custom default sets all children Def attributes to D3. And inherits all settings from D2.

All root variable rows without Def attribute will have set Def='D4'

Has Def='Fixed' (has AType='Text', because all undefined Type are 'Text')



Has Def='D4' because of setting Root CDef (has AType='Lines')
Has Def='D1' because of its own setting (has AType='Int')
Has Def='D4' because of its parent CDef setting (has AType='Lines')

Example of changing default row

This example shows updating row when it gets children and becomes parent row or looses its children and becomes empty.
The change can be done by adding new row, deleting row or moving row.

<Grid>
<Cfg MainCol="A"/>
<Cols>
<C Name="A" Width="500"/>
</Cols>
<Def>
<D Name="R" DefParent="Node" DefEmpty="Item"/>
<D Name="R" CDef="Item"/>
<D Name="Node" Color="220,220,200"/>
<D Name="Item"/>
</Def>
<Root CDef="Item"/>
<Body>
<B>
<I Def="Node" A="1">
<I A="1-1"/>
</I>
<I A="2"/>
<I A="3"/>
<I A="4"/>
</B>
</Body>
</Grid>






Any row if becomes parent its Def is set to "Node" and if becomes empty the Def is set to "Item".
Any row's new children will have set Def="Item". Any children without Def has Def="Item".
Parent row is colored, to show the change.


Any new root rows will have set Def="Item". Any root rows without Def has Def="Item".


It is parent row, so it has explicitly set Def="Node".
This child has set Def="Item" due setting <D Name="R" CDef="Item"/>.

This and next children have set Def=”Item” due setting <Root CDef="Item"/>.

Items related to default rows

<D> string

Name

required attribute
Name of the default row. Required. This name is referenced in row attributes Def, CDef, AcceptDef, DefEmpty, DefParent.
Any custom name can be used for default row, but there are predefined default row names (in Defaults.xml):
"R" - default row for all rows and defaults without Def attribute.
"Fixed" - default row for all fixed (head and foot) rows without Def attribute. Except Header. By default it inherits the Def "R".
"Solid" - default row for all solid space rows without Def attribute.
"Header" - default row for all Header rows.
"Group" - default row for all created grouping rows (parent rows automatically created when grouping). By default it inherits the Def "R".
In fact, any default with Group = '1' is default for grouping rows.
upd 10.0 <I><D> string

Def

["R"]
The name of default row <D> used for this row or default row. From this default the row inherits (reads) all its not set attribute values.
In <D> tag is this attribute is used only during loading data - fills the default by values from its parent default (and its parents).
Since 10.0 the <D Def/> can contain more default names, comma separated. But the <I Def/> can contain only one default!
If the <D Def/> derives from more default rows and they define the same attribute, the first default row listed in Def is used.
In space row it is not possible to define cells in the Def, use Mirror attribute instead.
API TRow var. TRow

Def

read only
On runtime the row Def attribute points to default row object instead of its name, the Def name is accessible by row.Def.Name.
upd 6.0 <I><Root> string

CDef

["R"]
The name of default row for row's children. This value is used as child's Def attribute value only for children without its own Def attribute set.
This attribute is used only on load, here it fills the row Def attribute value.
This value is also used as value of Def attribute for new child rows added to this parent.
The <Root CDef/> controls all root variable rows (like children of the hidden root row).
new 6.0 <I><Root> string[ ]

AcceptDef

Comma separated array of names of default rows that are accepted as children of this row.
Only rows with Def attribute present in this array can be moved or copied to the row's children.
If this attribute is missing, the row accepts all rows. If it is empty, it accepts no rows.
The <Root AcceptDef/> controls moving and copying into root (like children of the hidden root row).
new 6.0 <I> string

DefEmpty

Name of default row that will be set to row's Def attribute when the row loses all its children.
After change the row will be re-rendered to show all the changes related to the change.
This attribute is used only after the change, not on loading, on loading the row should have set correct Def attribute.
Hidden rows are valid children, but deleted rows (even visible) are not children!
new 6.0 <I> string

DefParent

Name of default row that will be set to row's Def attribute when the row gets first children and becomes parent row.
After change the row will be re-rendered to show all the changes related to the change.
This attribute is used only after the change, not on loading, on loading the row should have set correct Def attribute.
Hidden rows are valid children, but deleted rows (even visible) are not children!
API variable TRow[ ]

Def

Named array of all default rows in grid, including the base defaults: "R", "Fixed", "Solid", "Header" and "Group".
To access or change some default attribute value use grid.Def[def_name].attribute.
To get some row attribute including default value use global function Get(row,"attribute").
upd 6.4 API method void

ChangeDef

(TRow row, string def, bool show = 1, bool undo = 0)
Changes Def attribute of the row to default named def. If show = 1 it refreshes row and shows the changes.
It does not update row values, so cell types should not be changed by switching to the new default or must be updated externally.
new 7.0 API event string

OnChangeDef

(TGrid grid, TRow row, string def)
Called when changing default row due DefEmpty and DefParent.
It is called before the change, def is name of the new default row.
Return different default row name to change it, or null to continue or empty string to suppress the change.
It is called from ChangeDef method.