Updating UDGrid

Hi all,

I’ve got a page with selections at the top, then a button to load the grid.

When the page first loads, it displays waiting for selection as it should

The user then picks the options and hits the button and the grid loads as it should

However if they then change the selections at the top and press the button nothing happens. However if they refresh the page, the grid automatically loads with the correct details.

What am I doing wrong?

New-UDPage  -Name "Weighman Tickets"  -AuthorizationPolicy "IT" -Icon link -Content {
    New-UDCard -Content {
        New-UDRow -Columns {
            New-UDColumn -SmallOffset 2 -Size 3  -Content {
                New-UDSelect -Id "siteselect"  -Label " " -Option {
                    New-UDSelectOption -Name "Select site" -Value " "
                    $cache:sites = get-sites
                    $cache:sites | ForEach-Object { New-UDSelectOption -Name "$($_.site_code) $($_.site_name)" -Value "$($_.site_code)" }
                } -OnChange {
                    Write-UDLog -Level Info -Message "Custom:  Setting site selected to: $eventdata"
                    $SiteSelected = $eventdata
                }
            }

            New-UDColumn -Size 3 -Content {
                New-UDDatePicker -Id "Picker"
            }

            New-UDColumn -Size 3 -Content {
                New-UDHtml -Markup "<br></br>"
                New-UDButton -Id "getticketbutton" -Text "Get tickets" -OnClick {

                    $start = ([DateTime][String](Get-UDElement -Id "Picker").Attributes.from).ToString('yyyy-MM-dd')
                    $end = ([DateTime][String](Get-UDElement -Id "Picker").Attributes.to).ToString('yyyy-MM-dd')

                    Write-UDLog -Level Info -Message "Custom:  Trying to get weighticket list...  $start, $end, $((Get-UDElement -Id 'siteselect').Attributes['value'])"

                    $session:tickets = get-Weightickets -Start $start -End $end -SiteSelected $((Get-UDElement -Id "siteselect").Attributes['value'])
                    
                    Sync-UDElement -id Heading -Broadcast
                } 
            }
        }

        New-UDRow   -Columns {
            New-UDColumn -id 'Heading' -SmallOffset 3 -SmallSize 6 -Endpoint {
                Write-UDLog -Level info -Message "Site is |$($SiteSelected)|"
                if ([string]::IsNullOrEmpty($session:tickets)) {
                    Write-UDLog -Level Info -Message "Custom:  No selection as yet"
                    New-UDHeading  -Text "Waiting for selection..."
                }
                else {
                    New-UDGrid -id 'weighticketgrid' -Title "Showing weightickets for $($SiteSelected)" -PageSize 50  -Endpoint {
                        Write-UDLog -Level Info -Message "Custom:  Result: session:tickets"
                        $session:tickets | ForEach-Object {
                            [PSCustomObject]@{
                                #ID               = $_.ID
                                SiteCode         = $_.SiteCode
                                RegistrationCode = $_.RegistrationCode
                                TransactionDate  = $_.TransactionDate
                                TransactionNo    = $_.TransactionNo
                                SequenceCode     = $_.SequenceCode
                                Resend           = New-UDButton -Text "Details" -onclick {
                                    Show-UDModal -Persistent -Width '98%' -Content {
                                        New-UDButton -Text "Replay"  -OnClick {
                                            Replay-Weighticket -TransactionNo $_.TransactionNo -TransactionID $_.ID -sitecode $_.SiteCode
                                            Show-UDToast -Message "Replayed $($_.TransactionNo)" -Duration 10000
                                        }
                                        New-UDButton -Text 'Close' -OnClick {
                                            Hide-UDModal
                                        }
                                        New-UDGrid -id 'auditdetailgrid' -Title "Showing audit details for $($_.TransactionNo)" -AutoRefresh -RefreshInterval 300 -PageSize 50  -Endpoint {
                                            Get-WeighticketAudit -TransactionNo $_.TransactionNo | Out-UDGridData
                                        }   
                                    }
                                }
                            }
                        } | Out-UDGridData
                    }
                }
            }
        }
    }
}

Add

sync-udelement -id ‘weighticketgrid’

to the button. (I see you need both.)

That worked thank you! I thought if I refreshed the column, then it would refresh the grid which is contained in it, but obviously not :smiley:

well I would say it should have worked :slight_smile:
but you should really be carefull with nested endpoints. (in another word, you should avoid it at all cost.)

Oh really? Is there a better way to do it?

in your case here, I dont think so.
it were just a foot note :wink:

also, are you sure you want to use that -broadcast ?
if im not mistaken, it will refresh for all users of the same page.

After you posted the solution I realised that and removed it - thanks :slight_smile: