Closed AaronICT closed 1 year ago
Based on this thread, https://stackoverflow.com/questions/69552378/is-there-any-way-to-align-the-table-contents-in-the-same-line-in-the-teams-bot-f, I modified the final else statement in the New-AdaptiveTable function from this:
New-AdaptiveColumnSet {
for ($i = 0; $i -lt $DataTable[0].PSObject.Properties.Name.Count; $i++) {
New-AdaptiveColumn {
$HeaderText = $DataTable[0].PSObject.Properties.Name[$i]
New-AdaptiveTextBlock @HeaderAdaptiveTextBlockSplat -Text $HeaderText
for ($j = 0; $j -lt $DataTable.Count; $j++) {
$Value = $DataTable[$j].PSObject.Properties.Value[$i]
New-AdaptiveTextBlock @ContentAdaptiveTextBlockSplat -Text $Value -Separator
}
} -Width Stretch
}
}
to this:
$AdaptiveColumnSetSplat = @{
Separator = $false
}
for ($Row = 0; $Row -lt $DataTable.Count; $Row++) {
if ($Row -gt 0) { $AdaptiveColumnSetSplat.Separator = $true}
New-AdaptiveColumnSet {
for ($Column = 0; $Column -lt $DataTable[$Row].PSObject.Properties.Name.Count; $Column++) {
if ($Row -gt 0){
New-AdaptiveColumn {
$Value = $DataTable[$Row].PSObject.Properties.Value[$Column]
New-AdaptiveTextBlock @ContentAdaptiveTextBlockSplat -Text $Value
} -Width Stretch
} else {
New-AdaptiveColumn {
$HeaderText = $DataTable[$Row].PSObject.Properties.Name[$Column]
New-AdaptiveTextBlock @HeaderAdaptiveTextBlockSplat -Text $HeaderText
} -Width Stretch
}
}
} @AdaptiveColumnSetSplat
}
The other section of the if statement should be changed to, but for my immediate need this was enough. Let me know your thoughts... Thanks Aaron
I realized there was an issue with my work-a-round. Here is the revised version:
#Header
New-AdaptiveColumnSet {
for ($Column = 0; $Column -lt $DataTable[0].PSObject.Properties.Name.Count; $Column++) {
New-AdaptiveColumn {
$HeaderText = $DataTable[0].PSObject.Properties.Name[$Column]
New-AdaptiveTextBlock @HeaderAdaptiveTextBlockSplat -Text $HeaderText
} -Width Stretch
}
} -Separator
#data
for ($Row = 0; $Row -lt $DataTable.Count; $Row++) {
New-AdaptiveColumnSet {
for ($Column = 0; $Column -lt $DataTable[$Row].PSObject.Properties.Name.Count; $Column++) {
New-AdaptiveColumn {
$Value = $DataTable[$Row].PSObject.Properties.Value[$Column]
New-AdaptiveTextBlock @ContentAdaptiveTextBlockSplat -Text $Value
} -Width Stretch
}
}
}
@PrzemyslawKlys
Could you look at updating the module to include the above?
The way I see it in newest version:
# Lets prepare dummmy object array with few elements
$Objects = @(
[PSCustomObject] @{
"VeryLongTItleAlal dsadsadsdasd aslsqdasdsadasdasdasd" = 123
Test2 = "Tes1t"
Test3 = "Tes1t"
Test4 = "Tes1t"
}
[PSCustomObject] @{
"VeryLongTItleAlal dsadsadsdasd aslsqdasdsadasdasdasd" = 456
Test2 = "Test2"
}
[PSCustomObject] @{
"VeryLongTItleAlal dsadsadsdasd aslsqdasdsadasdasdasd" = 789
Test2 = "Test3"
}
)
# Lets create a new adaptive card
$Card = New-AdaptiveCard {
# lets add some text, table and line breaks
New-AdaptiveTextBlock -Size 'Medium' -Weight Bolder -Text 'Table usage with PSCustomObject 🔥' -Wrap
New-AdaptiveTable -DataTable $Objects -Width Auto
New-AdaptiveLineBreak
New-AdaptiveTable -DataTable $Objects -Width Stretch
} -Uri $Env:TEAMSPESTERID -FullWidth -ReturnJson
I am not sure what you think is wrong with this one?
Try testing it with lots of data. Prior to using @AaronICT's workaround, my output looksl ike this:
When a cell value is wrapped, the cells next to it do not adjust to the same height so the table rows are skewed. Here is a sample of what it looks like: https://i.stack.imgur.com/H02Eo.png Thanks Aaron