I have a simple table with two columns topic and type which are built on data from a sql query. I want to present the data in a New-UDTable but add a 3rd column for a button. I am struggling with how to either either add the button to each row of the datarow/array object or dynamically add it in with the columns flag. I’ve tried a few things but am really rusty on my PS and didn’t have luck getting things to work.
Hello @theabraxas long time no see, hope you keeping ok buddy? Well I remember I pulled this off once, I cannot remember the original ironman webpage I got to, to do this. So as I used it in SQL as well, here is a complete (almost) of one of my pages, that shows information in a table, and sums the total that customer spent, then you got an invoice button, which will then show the breakdown of each order in a new modal window…here is the code, hopefully from this you can figure it out for yourself:-
I remember this wasn’t the easiest thing to pull off, but the above code does work, so hopefully this will help you out You just need to change what is shown inside the modal that appears when the button is clicked and you should be good to go.
Thanks so much dude! Will be experimenting tonight that looks like I should be able to pick it apart, glad you’re still around here and building cool things!
Sorry I thought this quesiton had been asked before, I still cannot find the original blog, but does seem the ironman site has been some-what considerably updated. Anyways here is some more forum links on how to achieve this, so you got more than one example to work off of:-
I’m still hitting my head against a wall, I’ve tried a lot of things but none seem to be working. The closest I have made it is with this which I stole from another answer:
I’m assuming the whole $TableData .... $Body stuff is just supposed to work as I haven’t been able to find an example which actually defined $Body explicitly.
I’ve tried several other things like the following which just straight-up don’t work. Any ideas/answers would be tremendously appreciated!
I tried adding some variations of -columns and -properties and none of it worked. Not sure what’s supported in the current version versus what was only valid in older versions.
$Body only work if you are using server-side rendering via -LoadData parameter, if your data is static ( not pulling from SQL server for example) need to use -Data parameter
I think something like that used to work but I wasn’t able to get it working here. The below code does seem to work. Any comments/criticism greatly appreciated as I’m really bad at this
$data = Invoke-SqlCmd -ServerInstance $serverinstance -Database $databasename -Query "SELECT DISTINCT topic, type FROM topics"
$tabledata = @()
Foreach ($d in $data) {
$tableData += @{topic = $d.topic; type = $d.type}
}
$Columns = @(
New-UDTableColumn -Property type -Title Type
New-UDTableColumn -Property topic -Title Topic
New-UDTableColumn -Property edit -Title Edit -Render {
New-UDButton -text 'Edit' -OnClick {
Show-UDToast -Message "Someday I'll be able to edit"}
}
New-UDTableColumn -Property delete -Title Delete -Render {
New-UDButton -text 'Delete' -OnClick {
Show-UDModal -Content {
$topic = $eventdata.topic
$type = $eventdata.type
New-UDForm -Content {
New-UDCheckBox -Label "Check box and press submit to confirm deletion of $topic, click outside of this box to cancel." -Id 'Confirmation'
} -OnSubmit {
If ((Get-UDElement -Id 'Confirmation').checked -eq $true) {
Show-UDToast -Message "Deleting $topic"
Invoke-SqlCmd -ServerInstance $serverinstance -Database $databasename -Query "DELETE FROM topics WHERE topic=$topic AND type=$type"
Start-sleep -Seconds 3
Hide-UDModal
}
Else {
Show-UDToast -Title 'Checkbox' -Message "NOT deleting $topic."
Start-sleep -Seconds 3
Hide-UDModal
}
}
}-FullWidth -MaxWidth 'md'
}
}
)
New-UDTable -Data $tableData -Columns $Columns -sort -export -ShowFilter
}