PxPlus User Forum

Main Board => Discussions => Language => Topic started by: Tom Anderson on July 03, 2025, 11:12:15 AM

Title: Sort on Hdr Click
Post by: Tom Anderson on July 03, 2025, 11:12:15 AM
I know you can set a sort for a grid column by clicking on a column header if enabled in the grid creation in Nomads.

Question: can you get the grid to sort on a particular column using code from within a program? In other words, cause the grid sort without user intervention.

Thanks!

Tom Anderson
Title: Re: Sort on Hdr Click
Post by: James Zukowski on July 03, 2025, 11:33:15 AM
Have you tried using grd'sort=col_num or grd'sort$="Col Name" ...?
Title: Re: Sort on Hdr Click
Post by: Tom Anderson on July 03, 2025, 01:33:09 PM
James,

I tried the following but it doesn't work:

04550 LET GRID'SORT=5
04560 !
04570 GRID LOAD INPF_GRID.CTL,0,0,RR$

Suggestions?

Tom
Title: Re: Sort on Hdr Click
Post by: James Zukowski on July 03, 2025, 02:23:10 PM
Try the LOAD first, then the SORT.
Title: Re: Sort on Hdr Click
Post by: Loren Doornek on July 03, 2025, 02:51:14 PM
If your grid is named INPF_GRID, then you should use INPF_GRID.CTL'sort=5 (or -5 if you want to sort in reverse order).  You need to set the 'sort value AFTER data is loaded, and set it again if you reload the grid so that the newly-loaded data is sorted as expected. 

Whenever I need to reload a sorted item (grid or listbox), I will store the current sort that the user has selected using logic like "LET cur_sort=INPF_GRID.CTL'SORT". Then, after reloading the data in the grid/listbox, I'll set the sort back to whatever the user had previously selected using "LET INPF_GRID.CTL'SORT=cur_sort"
Title: Re: Sort on Hdr Click
Post by: Tom Anderson on July 03, 2025, 04:14:17 PM
Got it to work!

Thanks for the assist.

Tom