Adding a button to each row in a table

New-UDPage -Name “Password Updater” -Content {
$RDMvaults = Get-RDMVault
$cache:RDMpasswordLists = “”
$cache:Passwords = “”
$cache:PLS = 0
New-UDHeading -Text “Update clients password” -Size 1

New-UDSelect -id selectaclient -Label "Select a client" -option {
	New-UDSelectOption -name "Select a client" -Value 0
	foreach ($RDMvault in $RDMvaults)
	{
		New-UDSelectOption -name $RDMvault.name -Value $RDMvault.name
	}
}-OnChange { 
	$Selectedclient = $RDMvaults | where {$_.name -like (Get-UDElement -id "selectaclient")["value"]}
	Set-RDMCurrentRepository $Selectedclient.id
	$cache:RDMpasswordLists = Get-RDMSession | where {$_.ConnectionType -eq "Credential"} | select name,id
	$cache:PLS = 1
	Sync-UDElement -id PasswordList
}

New-UDDynamic -id PasswordList -content {
	New-UDSelect -id "passswordselect" -Label "Select a Password List" -option {
		if ($cache:PLS -eq 0)
		{
			New-UDSelectOption -name "Select a password list" -Value 0
		}else{
			New-UDSelectOption -name "Select a password list" -Value 0
			foreach ($RDMpasswordList in $cache:RDMpasswordLists)
			{
				New-UDSelectOption -name $RDMpasswordList.name -Value $RDMpasswordList.name
			}
		}
	}-OnChange { 
		Show-UDToast -Message (Get-UDElement -id 'passswordselect')["value"]
		Sync-UDElement -id Passwords
	}
}

New-UDDynamic -id Passwords -content {
	if ((Get-UDElement -id 'passswordselect')["value"] -ne 0)
	{	
		$Passwords = (Get-RDMSession -name (Get-UDElement -id passswordselect)["value"]).Credentials.passwordlist | select Host,User,ID
		$cache:PasswordTable  = @(
			Foreach ($password in $Passwords)
			{
				[PSCustomObject]@{
					Host = $password.Host
					User = $password.User
					#Edit = New-UDButton -id $password.id -Text 'Edit'
				}
			}
		)
		New-UDTable -Data $cache:PasswordTable 
	}
}

}

Hey So using the above if I uncomment out the Edit = New-UDButton -id $password.id -Text ‘Edit’ this crashes the page:

Error: Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=TypeError%3A%20Cannot%20read%20property%20’scrollWidth’%20of%20null&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

in p
in ForwardRef
in ForwardRef
in div
in ForwardRef
in ForwardRef
in div
in ForwardRef
in ForwardRef
in ForwardRef
in ForwardRef
in u
in Dashboard
in t
in div
in t
in t
in n

Any ideas?

I wonder if its because you don’t have -OnClick in there? So it doesn’t know what to do with the button.

I tried that as I had the same thought yet it gives the same error.

Any other thoughts? This is stopping me compleating this dashboard and I really could use some help.

		New-UDInputField -Type "textbox" -Name "accLookup" -Placeholder "Enter Name"
	} -Endpoint {
		param($accLookup)
		# Takes the input from above and searches $Cache:AllUsers to see if we have a match.
		$Objects = $Cache:AllUsers | Where-Object {($_.DisplayName -like "*$accLookup*") -or ($_.SamAccountName -like "*$accLookup*") -or ($_.name -like "*$accLookup*")}
		# We found some matches in $Cache:AllUsers, lets list them out.
		Set-UDElement -Id "results" -Content {
			New-UDGrid -Id "$accLookup Results" -Title "Search Results for: $accLookup" -Headers @("Username", "Name", "More Info", "Password Reset") -Properties @("Username", "Name", "MoreInfo", "ResetPW") -Endpoint {
				$Objects | ForEach-Object {
					$sid = $_.SamAccountName
					[PSCustomObject]@{
						Username = $_.UserPrincipalName
						Name     = $_.DisplayName
						# This button will load a dynamic page that gives more options
						MoreInfo = New-UDButton -Text "Get Details" -OnClick {Invoke-UDRedirect -Url "/$sid"} -Id "$sid Get Details"
						# This button will reset their password.
						ResetPW  = New-UDButton -Text "Reset Password" -OnClick {Invoke-UDRedirect -Url "mailto:[[REDACTED]]?cc=$($_.UserPrincipalName)&subject=PW Reset - $($_.Surname)&body=$($_.UserPrincipalName)" } -Id "$sid Reset Password"
					}
				} | Out-UDGridData
			}
		}
	}

Best i can offer is this, which is what i use in my dashboard. However, this is a 2.9 dashboard and not a Universal one because i haven’t had the motivation to rebuild everything to migrate to PSU.

Yeah problem is I am running PU on version 3 so maybe this is a diffrent issue. V2 stuff works the way you do it above. I am currently building new things in 3 and moving over v2 stuff slowly.

Don’t put the button in the data. Add a custom column and render the button that way.

The docs\example are here: https://docs.ironmansoftware.com/dashboard/components/data-display/table#table-with-custom-column-rendering

Ok ill go play with that and see if I can get it to work. Does that mean V3 does not support this in objects now?

Does that button know the details of its row and can it get information form there?

You might be able to do it the old way but it breaks sorting, search, filtering etc.

And it does know the details of the row:

New-UDTableColumn -Property Dessert -Title Dessert -Render { 
# Body is the row data here
        $Item = $Body | ConvertFrom-Json 
        New-UDButton -Id "btn$($Item.Dessert)" -Text "Click for Dessert!" -OnClick { Show-UDToast -Message $Item.Dessert } 
    }

Thanks so much, got it and it looks good. Now I know ill keep using the new way of doing things.

Just put in a order for the license too :smiley:

Thanks

On the table I have filtering enabled is there a way to remove this from the button column?

you can specify it for each column

for example

$Data | Out-UDTableData -Page $TableData.page -TotalCount $count -Properties $TableData.properties
            } -Columns @(
                New-UDTableColumn -Property 'Name' -Sort $true -Filter $true
                New-UDTableColumn -Property 'Description' -Sort $true -Filter $false

When I do this no filter is offered, I did try this before as I did see that, the table however does not have the filter option.

I did just work it out,

you need the -filter option in the New-UDTable and then you can disable the filter on a column with -filter $false :smiley: