Skip to content

Commit e7f81f0

Browse files
Improve transpose #316
1 parent abda18e commit e7f81f0

File tree

3 files changed

+107
-6
lines changed

3 files changed

+107
-6
lines changed

CHANGELOG.MD

+53-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,60 @@
44
Unfortunetly some code is very old, some code doesn't serve it's purpose anymore, and requires heavy changes that may have an impact on already deployed code.
55
Please make sure to read changes before updating, as we're undergoing some breaking changes.
66

7+
## 1.21.0 - 2024.06.29
8+
- Changed behavior of `Transpose` in `New-HTMLTable` / `Out-HtmlView`
9+
- Added `TransposeLegacy` to `New-HTMLTable` / `Out-HtmlView` to keep old behavior
10+
- Added `TransposeName` to `New-HTMLTable` / `Out-HtmlView` to allow for custom name (default is `Object 0`, `Object 1`, `Object 2`)
11+
- Added `TransposeProperty` to `New-HTMLTable` / `Out-HtmlView` to allow for transposing on unique value from specific property (ex. ServerName)
12+
- Added `Out-HtmlView` additional options `PrettifyObject, PrettifyObjectSeparator, PrettifyObjectDateTimeFormat`
13+
14+
Those changes resolve: [#316](https://github.com/EvotecIT/PSWriteHTML/issues/316)
15+
16+
```powershell
17+
$Object = @(
18+
[PSCustomObject] @{
19+
Test = 5
20+
Ello = 'Motto'
21+
Hello = 'Totto'
22+
}
23+
[PSCustomObject] @{
24+
Test = 5
25+
Ello = 'Motto'
26+
Hello = 'Totto'
27+
}
28+
[PSCustomObject] @{
29+
Test = 5
30+
Ello = 'Motto'
31+
Hello = 'Totto'
32+
}
33+
[PSCustomObject] @{
34+
Test = 5
35+
Ello = 'Motto'
36+
Hello = 'Totto'
37+
}
38+
[PSCustomObject] @{
39+
Test = 5
40+
Ello = 'Motto'
41+
Hello = 'Totto'
42+
}
43+
[PSCustomObject] @{
44+
Test = 3
45+
Ello = 'Lotto'
46+
Hello = 'Totto'
47+
}
48+
)
49+
50+
51+
$Object | Out-HtmlView -Transpose -TransposeName 'Test ' -Filtering
52+
53+
New-HTML -TitleText $Title -Online -FilePath $PSScriptRoot\Example-TableTranspose01.html {
54+
New-HTMLTable -DataTable $Object -Filtering -Transpose
55+
} -ShowHTML
56+
```
57+
758
## 1.20.0 - 2024.06.27
8-
- Added to `EmailTable` / `New-HTMLTable` additional properties `PrettifyObject, PrettifyObjectSeparator, PrettifyObjectDateTimeFormat`
9-
- Added to `New-HTMLTableOption` additional properties `PrettifyObject, PrettifyObjectSeparator, PrettifyObjectDateTimeFormat`
59+
- Added to `EmailTable` / `New-HTMLTable` additional options `PrettifyObject, PrettifyObjectSeparator, PrettifyObjectDateTimeFormat`
60+
- Added to `New-HTMLTableOption` additional options `PrettifyObject, PrettifyObjectSeparator, PrettifyObjectDateTimeFormat`
1061

1162
Those options above allow object to be translated to more readable format when using properties that are arrays or when wanting different datetime format
1263
It basically does to HTML version what normally is doable in JavaScript DataStore.

Public/New-HTMLTable.ps1

+26-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,16 @@ function New-HTMLTable {
223223
Parameter description
224224
225225
.PARAMETER Transpose
226-
Parameter description
226+
Transpose table. This is useful when you have objects and you want to transpose them.
227+
228+
.PARAMETER TransposeProperty
229+
Transpose table based on property. By default it's "Object X". This makes sense if you have unique value per object that you want to transpose table based on.
230+
231+
.PARAMETER TransposeName
232+
Name of the column that will be used per object to transpose table. By default it's "Object X", "Object Y", "Object Z" etc.
233+
234+
.PARAMETER TransposeLegacy
235+
Use old method of transposing table. This is useful when you have objects and you want to transpose them, using legacy method.
227236
228237
.PARAMETER OverwriteDOM
229238
Parameter description
@@ -339,6 +348,9 @@ function New-HTMLTable {
339348
[alias('DataTableName')][string] $DataTableID,
340349
[string] $DataStoreID,
341350
[switch] $Transpose,
351+
[string] $TransposeProperty,
352+
[string] $TransposeName,
353+
[switch] $TransposeLegacy,
342354
[string] $OverwriteDOM,
343355
[switch] $SearchHighlight,
344356
[switch] $AlphabetSearch,
@@ -424,7 +436,19 @@ function New-HTMLTable {
424436

425437
if ($Transpose) {
426438
# Allows easy conversion from PSCustomObject to Hashtable and vice versa
427-
$DataTable = Format-TransposeTable -Object $DataTable
439+
$formatTransposeTableSplat = @{
440+
AllObjects = $DataTable
441+
}
442+
if ($TransposeProperty) {
443+
$formatTransposeTableSplat['Property'] = $TransposeProperty
444+
}
445+
if ($TransposeName) {
446+
$formatTransposeTableSplat['Name'] = $TransposeName
447+
}
448+
if ($TransposeLegacy) {
449+
$formatTransposeTableSplat['Legacy'] = $true
450+
}
451+
$DataTable = Format-TransposeTable @formatTransposeTableSplat
428452
}
429453
if ($FlattenObject) {
430454
if ($FlattenDepth) {

Public/Out-HTMLView.ps1

+28-2
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,20 @@ function Out-HtmlView {
100100
[ValidateSet('top', 'bottom')][string] $SearchBuilderLocation = 'top',
101101
[ValidateSet('HTML', 'JavaScript', 'AjaxJSON')][string] $DataStore,
102102
[switch] $Transpose,
103+
[string] $TransposeProperty,
104+
[string] $TransposeName,
105+
[switch] $TransposeLegacy,
103106
[switch] $PreventShowHTML,
104107
[switch] $Online,
105108
[string] $OverwriteDOM,
106109
[switch] $SearchHighlight,
107110
[switch] $AlphabetSearch,
108111
[switch] $FuzzySearch,
109112
[switch] $FuzzySearchSmartToggle,
110-
[switch] $FlattenObject
113+
[switch] $FlattenObject,
114+
[switch] $PrettifyObject,
115+
[string] $PrettifyObjectSeparator = ", ",
116+
[string] $PrettifyObjectDateTimeFormat
111117
)
112118
Begin {
113119
$DataTable = [System.Collections.Generic.List[Object]]::new()
@@ -177,7 +183,6 @@ function Out-HtmlView {
177183
Simplify = $Simplify
178184
HideShowButton = $HideShowButton
179185
CompareReplace = $CompareReplace
180-
Transpose = $Transpose
181186
SearchRegularExpression = $SearchRegularExpression
182187
WordBreak = $WordBreak
183188
AutoSize = $AutoSize
@@ -205,6 +210,27 @@ function Out-HtmlView {
205210
FlattenObject = $FlattenObject
206211
CompareNames = $CompareNames
207212
}
213+
if ($Transpose) {
214+
$newHTMLTableSplat['Transpose'] = $Transpose.IsPresent
215+
if ($TransposeProperty) {
216+
$newHTMLTableSplat['TransposeProperty'] = $TransposeProperty
217+
}
218+
if ($TransposeName) {
219+
$newHTMLTableSplat['TransposeName'] = $TransposeName
220+
}
221+
if ($TransposeLegacy) {
222+
$newHTMLTableSplat['TransposeLegacy'] = $TransposeLegacy
223+
}
224+
}
225+
if ($PrettifyObject) {
226+
$newHTMLTableSplat['PrettifyObject'] = $PrettifyObject.IsPresent
227+
if ($PrettifyObjectSeparator) {
228+
$newHTMLTableSplat['PrettifyObjectSeparator'] = $PrettifyObjectSeparator
229+
}
230+
if ($PrettifyObjectDateTimeFormat) {
231+
$newHTMLTableSplat['PrettifyObjectDateTimeFormat'] = $PrettifyObjectDateTimeFormat
232+
}
233+
}
208234
Remove-EmptyValue -Hashtable $newHTMLTableSplat
209235
New-HTMLTable @newHTMLTableSplat
210236

0 commit comments

Comments
 (0)