From 86d00aa9ba74c38f8a3d13c3a1466eb8fe201612 Mon Sep 17 00:00:00 2001 From: opustecnica Date: Thu, 2 Jan 2020 08:00:33 -0500 Subject: [PATCH 1/9] Update New-TableConditionalFormatting.ps1 --- Private/Tables/New-TableConditionalFormatting.ps1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Private/Tables/New-TableConditionalFormatting.ps1 b/Private/Tables/New-TableConditionalFormatting.ps1 index b481774d..6b4bf3d3 100644 --- a/Private/Tables/New-TableConditionalFormatting.ps1 +++ b/Private/Tables/New-TableConditionalFormatting.ps1 @@ -34,6 +34,7 @@ function New-TableConditionalFormatting { if ($null -eq $Condition.Type -or $Condition.Type -eq 'number' -or $Condition.Type -eq 'int' -or $Condition.Type -eq 'decimal') { "if (data[$ConditionHeaderNr] $($Condition.Operator) $($Condition.Value)) {" } elseif ($Condition.Type -eq 'string') { + <# switch ($Condition.Operator) { "contains" { "if (data[$($ConditionHeaderNr)].includes('$($Condition.Value)')) {" @@ -45,6 +46,17 @@ function New-TableConditionalFormatting { "if (data[$ConditionHeaderNr] $($Condition.Operator) '$($Condition.Value)') {" } } + #> + # [BEGIN] Proposed change to handle IE11 JS shortcomings + switch -Regex ($Condition.Operator) { + "contains|like" { + "if (data[$($ConditionHeaderNr)].indexOf('$($Condition.Value)') >= 0 ) {" + } + default { + "if (data[$ConditionHeaderNr] $($Condition.Operator) '$($Condition.Value)') {" + } + } + # [END] Proposed change to handle IE11 JS shortcomings } elseif ($Condition.Type -eq 'date') { "if (new Date(data[$ConditionHeaderNr]) $($Condition.Operator) new Date('$($Condition.Value)')) {" } @@ -66,4 +78,4 @@ function New-TableConditionalFormatting { $Options = $Options -Replace ($TextToFind, $Condition) } return $Options -} \ No newline at end of file +} From 954ebebc23c3d9b0c7517ea2d1eaa8e007fe5ea5 Mon Sep 17 00:00:00 2001 From: opustecnica Date: Sat, 4 Jan 2020 14:53:39 -0500 Subject: [PATCH 2/9] Update New-TableConditionalFormatting.ps1 --- Private/Tables/New-TableConditionalFormatting.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Private/Tables/New-TableConditionalFormatting.ps1 b/Private/Tables/New-TableConditionalFormatting.ps1 index 6b4bf3d3..22ed914d 100644 --- a/Private/Tables/New-TableConditionalFormatting.ps1 +++ b/Private/Tables/New-TableConditionalFormatting.ps1 @@ -50,7 +50,9 @@ function New-TableConditionalFormatting { # [BEGIN] Proposed change to handle IE11 JS shortcomings switch -Regex ($Condition.Operator) { "contains|like" { - "if (data[$($ConditionHeaderNr)].indexOf('$($Condition.Value)') >= 0 ) {" + # "if (data[$($ConditionHeaderNr)].indexOf('$($Condition.Value)') >= 0 ) {" + # [Case Insensitive] Allow for case insensitive lookups when using "contains|like" + "if (/$($Condition.Value)/i.test(data[$($ConditionHeaderNr)])) {" } default { "if (data[$ConditionHeaderNr] $($Condition.Operator) '$($Condition.Value)') {" From f6d5d4d2411b1b9783c7a968af92be36f063fcb2 Mon Sep 17 00:00:00 2001 From: opustecnica Date: Sat, 4 Jan 2020 16:00:09 -0500 Subject: [PATCH 3/9] Update New-TableConditionalFormatting.ps1 --- .../Tables/New-TableConditionalFormatting.ps1 | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/Private/Tables/New-TableConditionalFormatting.ps1 b/Private/Tables/New-TableConditionalFormatting.ps1 index 22ed914d..fe356130 100644 --- a/Private/Tables/New-TableConditionalFormatting.ps1 +++ b/Private/Tables/New-TableConditionalFormatting.ps1 @@ -34,31 +34,14 @@ function New-TableConditionalFormatting { if ($null -eq $Condition.Type -or $Condition.Type -eq 'number' -or $Condition.Type -eq 'int' -or $Condition.Type -eq 'decimal') { "if (data[$ConditionHeaderNr] $($Condition.Operator) $($Condition.Value)) {" } elseif ($Condition.Type -eq 'string') { - <# - switch ($Condition.Operator) { - "contains" { - "if (data[$($ConditionHeaderNr)].includes('$($Condition.Value)')) {" - } - "like" { - "if (data[$($ConditionHeaderNr)].includes('$($Condition.Value)')) {" - } - default { - "if (data[$ConditionHeaderNr] $($Condition.Operator) '$($Condition.Value)') {" - } - } - #> - # [BEGIN] Proposed change to handle IE11 JS shortcomings switch -Regex ($Condition.Operator) { "contains|like" { - # "if (data[$($ConditionHeaderNr)].indexOf('$($Condition.Value)') >= 0 ) {" - # [Case Insensitive] Allow for case insensitive lookups when using "contains|like" - "if (/$($Condition.Value)/i.test(data[$($ConditionHeaderNr)])) {" + "if (/$($Condition.Value.Replace('*',''))/i.test(data[$($ConditionHeaderNr)])) {" } default { "if (data[$ConditionHeaderNr] $($Condition.Operator) '$($Condition.Value)') {" } } - # [END] Proposed change to handle IE11 JS shortcomings } elseif ($Condition.Type -eq 'date') { "if (new Date(data[$ConditionHeaderNr]) $($Condition.Operator) new Date('$($Condition.Value)')) {" } From 71ff5b8f1f6422dd342827860ff939fa65513beb Mon Sep 17 00:00:00 2001 From: opustecnica Date: Sat, 4 Jan 2020 19:04:17 -0500 Subject: [PATCH 4/9] Update New-TableConditionalFormatting.ps1 --- Private/Tables/New-TableConditionalFormatting.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Private/Tables/New-TableConditionalFormatting.ps1 b/Private/Tables/New-TableConditionalFormatting.ps1 index fe356130..6d6566bb 100644 --- a/Private/Tables/New-TableConditionalFormatting.ps1 +++ b/Private/Tables/New-TableConditionalFormatting.ps1 @@ -36,7 +36,7 @@ function New-TableConditionalFormatting { } elseif ($Condition.Type -eq 'string') { switch -Regex ($Condition.Operator) { "contains|like" { - "if (/$($Condition.Value.Replace('*',''))/i.test(data[$($ConditionHeaderNr)])) {" + "if (/$($Condition.Value.Replace('*','.*'))/i.test(data[$($ConditionHeaderNr)])) {" } default { "if (data[$ConditionHeaderNr] $($Condition.Operator) '$($Condition.Value)') {" From cbde559b11068b64b230e23f03ba4d5aa33867d0 Mon Sep 17 00:00:00 2001 From: opustecnica Date: Thu, 9 Jan 2020 15:27:12 -0500 Subject: [PATCH 5/9] Update Add-TableFiltering.ps1 --- Private/Tables/Add-TableFiltering.ps1 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Private/Tables/Add-TableFiltering.ps1 b/Private/Tables/Add-TableFiltering.ps1 index b89363c8..fa02a174 100644 --- a/Private/Tables/Add-TableFiltering.ps1 +++ b/Private/Tables/Add-TableFiltering.ps1 @@ -3,8 +3,18 @@ function Add-TableFiltering { param( [bool] $Filtering, [ValidateSet('Top', 'Bottom', 'Both')][string]$FilteringLocation = 'Bottom', - [string] $DataTableName + [string] $DataTableName, + [switch]$RegularExpression ) + + if ($RegularExpression.IsPresent) { + [string]$JSDataTableRegEx = 'true' + [string]$JSDataTableSmart = 'false' + } else { + [string]$JSDataTableRegEx = 'false' + [string]$JSDataTableSmart = 'true' + } + $Output = @{} if ($Filtering) { # https://datatables.net/examples/api/multi_filter.html @@ -25,7 +35,7 @@ function Add-TableFiltering { `$('input', this.footer()).on('keyup change', function () { if (that.search() !== this.value) { - that.search(this.value).draw(); + that.search(this.value, $JSDataTableRegEx, $JSDataTableSmart).draw(); } }); }); @@ -65,7 +75,7 @@ function Add-TableFiltering { `$('input', this.footer()).on('keyup change', function () { if (that.search() !== this.value) { - that.search(this.value).draw(); + that.search(this.value, $JSDataTableRegEx, $JSDataTableSmart).draw(); } }); }); @@ -101,4 +111,4 @@ function Add-TableFiltering { $Output.FilteringTopCode = $Output.FilteringBottomCode = '' # assign multiple same values trick } return $Output -} \ No newline at end of file +} From 195e415eb19580cabc1951fa118ac3b7b13af3d3 Mon Sep 17 00:00:00 2001 From: opustecnica Date: Thu, 9 Jan 2020 15:31:46 -0500 Subject: [PATCH 6/9] Update New-HTMLTable.ps1 --- Public/New-HTMLTable.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Public/New-HTMLTable.ps1 b/Public/New-HTMLTable.ps1 index 304837ef..da1e1c7f 100644 --- a/Public/New-HTMLTable.ps1 +++ b/Public/New-HTMLTable.ps1 @@ -53,7 +53,8 @@ function New-HTMLTable { [alias('CompareWithColors')][switch] $HighlightDifferences, [int] $First, [int] $Last, - [alias('Replace')][Array] $CompareReplace + [alias('Replace')][Array] $CompareReplace, + [switch]$RegularExpression ) if (-not $Script:HTMLSchema.Features) { Write-Warning 'New-HTMLTable - Creation of HTML aborted. Most likely New-HTML is missing.' @@ -478,7 +479,7 @@ function New-HTMLTable { # Enable Custom Date fromat sorting $SortingFormatDateTime = Add-CustomFormatForDatetimeSorting -DateTimeSortingFormat $DateTimeSortingFormat - $FilteringOutput = Add-TableFiltering -Filtering $Filtering -FilteringLocation $FilteringLocation -DataTableName $DataTableID + $FilteringOutput = Add-TableFiltering -Filtering $Filtering -FilteringLocation $FilteringLocation -DataTableName $DataTableID -RegularExpression:$RegularExpression $FilteringTopCode = $FilteringOutput.FilteringTopCode $FilteringBottomCode = $FilteringOutput.FilteringBottomCode $LoadSavedState = Add-TableState -DataTableName $DataTableID -Filtering $Filtering -FilteringLocation $FilteringLocation -SavedState (-not $DisableStateSave) From 60f2e2df0807ec4d3c45bb941712c82d7d170f43 Mon Sep 17 00:00:00 2001 From: opustecnica Date: Fri, 10 Jan 2020 11:34:09 -0500 Subject: [PATCH 7/9] Update Add-TableFiltering.ps1 --- Private/Tables/Add-TableFiltering.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Private/Tables/Add-TableFiltering.ps1 b/Private/Tables/Add-TableFiltering.ps1 index fa02a174..0dcd4124 100644 --- a/Private/Tables/Add-TableFiltering.ps1 +++ b/Private/Tables/Add-TableFiltering.ps1 @@ -4,10 +4,10 @@ function Add-TableFiltering { [bool] $Filtering, [ValidateSet('Top', 'Bottom', 'Both')][string]$FilteringLocation = 'Bottom', [string] $DataTableName, - [switch]$RegularExpression + [alias('RegularExpression')][switch]$SearchRegularExpression ) - if ($RegularExpression.IsPresent) { + if ($SearchRegularExpression.IsPresent) { [string]$JSDataTableRegEx = 'true' [string]$JSDataTableSmart = 'false' } else { From 644d8db113b43d7fcb0de2905aa3b8452e4b99dd Mon Sep 17 00:00:00 2001 From: opustecnica Date: Fri, 10 Jan 2020 11:37:59 -0500 Subject: [PATCH 8/9] Update New-HTMLTable.ps1 --- Public/New-HTMLTable.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Public/New-HTMLTable.ps1 b/Public/New-HTMLTable.ps1 index da1e1c7f..3a6c1c91 100644 --- a/Public/New-HTMLTable.ps1 +++ b/Public/New-HTMLTable.ps1 @@ -54,7 +54,7 @@ function New-HTMLTable { [int] $First, [int] $Last, [alias('Replace')][Array] $CompareReplace, - [switch]$RegularExpression + [alias('RegularExpression')][switch]$SearchRegularExpression ) if (-not $Script:HTMLSchema.Features) { Write-Warning 'New-HTMLTable - Creation of HTML aborted. Most likely New-HTML is missing.' @@ -479,7 +479,7 @@ function New-HTMLTable { # Enable Custom Date fromat sorting $SortingFormatDateTime = Add-CustomFormatForDatetimeSorting -DateTimeSortingFormat $DateTimeSortingFormat - $FilteringOutput = Add-TableFiltering -Filtering $Filtering -FilteringLocation $FilteringLocation -DataTableName $DataTableID -RegularExpression:$RegularExpression + $FilteringOutput = Add-TableFiltering -Filtering $Filtering -FilteringLocation $FilteringLocation -DataTableName $DataTableID -SearchRegularExpression:$SearchRegularExpression $FilteringTopCode = $FilteringOutput.FilteringTopCode $FilteringBottomCode = $FilteringOutput.FilteringBottomCode $LoadSavedState = Add-TableState -DataTableName $DataTableID -Filtering $Filtering -FilteringLocation $FilteringLocation -SavedState (-not $DisableStateSave) From 9a71c85c57ad8be1d93eda3eb10cae52b0ed318d Mon Sep 17 00:00:00 2001 From: opustecnica Date: Fri, 10 Jan 2020 11:40:58 -0500 Subject: [PATCH 9/9] Create Example-SearchRegularExpression.ps1 --- .../Example-SearchRegularExpression.ps1 | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Examples/Example-SearchRegularExpression/Example-SearchRegularExpression.ps1 diff --git a/Examples/Example-SearchRegularExpression/Example-SearchRegularExpression.ps1 b/Examples/Example-SearchRegularExpression/Example-SearchRegularExpression.ps1 new file mode 100644 index 00000000..482657d7 --- /dev/null +++ b/Examples/Example-SearchRegularExpression/Example-SearchRegularExpression.ps1 @@ -0,0 +1,31 @@ +Import-Module PSWriteHTML -Force + +$Process = Get-Process | Select-Object -First 35 + +$Name = 'PSWriteHTML Regular Expression Search and Wildcard Conditional Formatting' +$Author = $env:USERNAME + +$SaveFilePath = $PSCommandPath -replace "ps1$", "html" + + +New-HTML -Name $Name -Author $Author -FilePath $SaveFilePath -AutoRefresh 0 -ShowHTML -UseCssLinks:$false -UseJavaScriptLinks:$false -HTMLData { + $Buttons = @('copyHtml5', 'excelHtml5', 'csvHtml5', 'pdfHtml5', 'pageLength') + $PreContent = { New-HTMLText -Text 'Smart Search Enabled for Column Searches' -Color DodgerBlue -Alignment center -FontSize 20 } + + New-HTMLTable -DataTable $Process -DefaultSortIndex 4 -ScrollCollapse -Buttons $Buttons -Filtering -FilteringLocation Bottom -FixedFooter -PreContent $PreContent -HTML { + # If item matches multiple rules, last matched rule is applied + New-HTMLTableCondition -Name Name -ComparisonType string -Operator like -Value "Co*" -BackgroundColor Crimson -Color White + New-HTMLTableCondition -Name Name -ComparisonType string -Operator like -Value "*me" -BackgroundColor Gold -Color Black + New-HTMLTableCondition -Name Name -ComparisonType string -Operator like -Value "C*de" -BackgroundColor Green -Color White + } + New-HTMLHorizontalLine + New-HTMLText -Text "RegEx Example - Search for all processes but 'Code': ^((?!Code).)*$" + New-HTMLText -Text "RegEx Example - Search for all processes but 'Code' OR 'Chrome': ^((?!Code|Chrome).)*$" + New-HTMLText -Text "RegEx Example - Search for all 'Code' OR 'Chrome' processes: Code|Chrome" + $PreContent = { New-HTMLText -Text 'Regular Expression Search Enabled for Column Searches' -Color DodgerBlue -Alignment center -FontSize 20 } + New-HTMLTable -DataTable $Process -DefaultSortIndex 4 -ScrollCollapse -Buttons $Buttons -Filtering -FilteringLocation Bottom -FixedFooter -PreContent $PreContent -SearchRegularExpression -HTML { + New-HTMLTableCondition -Name Path -ComparisonType string -Operator like -Value "*cri*" -BackgroundColor Crimson -Color White + New-HTMLTableCondition -Name Path -ComparisonType string -Operator like -Value "*me" -BackgroundColor Gold -Color Black + New-HTMLTableCondition -Name Path -ComparisonType string -Operator like -Value "C*de" -BackgroundColor Green -Color White + } +}