I have a hierarchical object structure like this:
public class Department
{
public string Name { get; set; }
public string Manager { get; set; }
public Employee[] Employees { get; set; }
}
public class Employee
{
public string Name { get; set;}
public string Speciallity { get; set; }
}
How can i create a custom .ps1xml file that will let me display Department(s)
as follows:
Department : Testers Manager : P.H. Boss Name Speciallity ---------- ----------------------------- Some Employee .Net Another Employee BizTalk Yet Another PowerShell ... ... Department : Developers Manager : Wally Name Speciallity ---------- ----------------------------- Some Employee .Net Another Employee BizTalk Yet Another PowerShell ... ...
The main problem i'm having is how i can define a <View>
item that is selected for a Department
, that is based on a TableControl
, but which displays the Department.Employees
in the table control.
I can display Employee
(s) perfectly fine using a View
:
<View>
<Name>Employee</Name>
<ViewSelectedBy>
<TypeName>Employee</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>Name</Label>
<Width>30</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>Speciallity</Label>
<Width>50</Width>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<Wrap/>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Speciallity</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
And i can format departments using a list format:
<View>
<Name>TestResultSet</Name>
<ViewSelectedBy>
<TypeName>Department</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<Label>Department</Label>
<PropertyName>Name</PropertyName>
</ListItem>
<ListItem>
<PropertyName>Manager</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
But how do i add a table of the employees after the department?
I think you need to make use of <GroupBy>...</GroupBy
and also <Control><CustomControl>...</CustomControl></Control>
Take a look at this ps1xml format file for DiscUtils module, haven't had the chance to play with it myself yet but it may put you on the right path.
See also the help about_Format.ps1xml
which has some info, though a little light on examples for some aspects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With