Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pass objects downstream when using the New-UDDataGrid -CheckboxSelection #4179

Open
BOF007 opened this issue Dec 29, 2024 · 0 comments
Labels
bug Something isn't working PowerShell Universal Issue relates to PowerShell Universal. requires triage Issue has not yet been verified by the development team. v5 Version 5 issue.

Comments

@BOF007
Copy link

BOF007 commented Dec 29, 2024

Description of Issue

I am having difficulty understanding how to pass data through to additional functions, after a user selects a row(s). with "New-UDDataGrid -CheckboxSelection"

I am using an app script

The data loads in shown by the toast but after selection and clicking the button no cell data gets passed through.

Also I'm having difficulty finding information on how to debug to console in an app I have tried the "Write-Debug" and I could not see any content appearing the in app's log tab. or the main log page under platform so I have been using makeshift toasts for logging.
image

$sampleData = @(
	[PSCustomObject]@{ Id = 1; Name = "John Doe"; EmailAddress = "[email protected]"; PrimaryNumber = "123-456-7890"; SecondaryNumber = "098-765-4321"; Title = "Manager"; Department = "Sales" }
	[PSCustomObject]@{ Id = 2; Name = "Jane Smith"; EmailAddress = "[email protected]"; PrimaryNumber = "234-567-8901"; SecondaryNumber = "987-654-3210"; Title = "Developer"; Department = "IT" }
	[PSCustomObject]@{ Id = 3; Name = "Alice Johnson"; EmailAddress = "[email protected]"; PrimaryNumber = "345-678-9012"; SecondaryNumber = "876-543-2109"; Title = "Analyst"; Department = "Finance" }
)

# Function to create a test page with a data grid
function New-TestPage {
	New-UDPage -Name "Test Page" -Url "/test" -Content {
		New-UDRow {
			New-UDColumn -Size 12 {
				New-UDDataGrid -id DataGrid -LoadRows {
					# Debug message to check data loading
					Show-UDToast -Message "Loading data: $($sampleData | Out-String)"
					$sampleData | Out-UDDataGridData -Context $EventData -TotalRows $sampleData.Count
				} -Columns @(
					New-UDDataGridColumn -Field 'Id' -HeaderName 'ID' -Hide $true
					New-UDDataGridColumn -Field 'Name' -HeaderName 'Name'
					New-UDDataGridColumn -Field 'EmailAddress' -HeaderName 'Email Address'
					New-UDDataGridColumn -Field 'PrimaryNumber' -HeaderName 'Primary Number'
					New-UDDataGridColumn -Field 'SecondaryNumber' -HeaderName 'Secondary Number'
					New-UDDataGridColumn -Field 'Title' -HeaderName 'Title'
					New-UDDataGridColumn -Field 'Department' -HeaderName 'Department'
				) -AutoHeight $true -AutoSizeColumns $true -PageSize 10 -Density "compact" -CheckboxSelection -CheckboxSelectionVisibleOnly -DisableRowSelectionOnClick
			}
		}
		New-UDRow {
			New-UDColumn -Size 12 {
				New-UDButton -Text 'Get Selected Rows' -OnClick {
					$SelectedRows = Get-UDElement -ID 'DataGrid'
					$SelectedUsers = $SelectedRows.selection
					
					# Debug message to check selected rows
					Show-UDToast -Message "Selected rows: $($SelectedUsers | Out-String)"
					
					# Display selected users in a toast notification
					if ($SelectedUsers -ne $null -and $SelectedUsers.Count -gt 0) {
						foreach ($user in $SelectedUsers) {
							$userDetails = "ID: $($user.Id), Name: $($user.Name), Email: $($user.EmailAddress), Primary Number: $($user.PrimaryNumber), Secondary Number: $($user.SecondaryNumber), Title: $($user.Title), Department: $($user.Department)"
							Show-UDToast -Message "Selected user: $userDetails"
						}
					} else {
						Show-UDToast -Message "No users selected."
					}
				}
			}
		}
	}
}

# Create the test page
$Pages = @()
$Pages += New-TestPage

New-UDApp -Title "Test App" -Pages $Pages

Version

5.1.2

Severity

Low

Hosting Method

MSI (Windows Service)

Operating System

Windows

Database

SQLite

Licensed

Yes

Features

No response

Additional Environment data

No response

Screenshots/Animations

No response

@BOF007 BOF007 added bug Something isn't working PowerShell Universal Issue relates to PowerShell Universal. requires triage Issue has not yet been verified by the development team. v5 Version 5 issue. labels Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PowerShell Universal Issue relates to PowerShell Universal. requires triage Issue has not yet been verified by the development team. v5 Version 5 issue.
Projects
None yet
Development

No branches or pull requests

1 participant