PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Preserving sort order when returning from Form to Table window
Preserving sort order when returning from Form to Table window
Débuté par Scott Daughtry, 28 nov. 2016 16:11 - 6 réponses
Posté le 28 novembre 2016 - 16:11
WD21 apps: from a Table window I double left click a table entry to display it's associated FORM window; when I exit the FORM window the table's sort order undoes itself. How can I capture the table's sort order before the FORM window opens and then restore it when the focus returns to the TABLE window (and is there a tweak I can make elsewhere in the RAD template) to stop this unwanted behavior?

Simple test to confirm this problem: on a TABLE, manually sort the table by clicking column headers on two different columns (e.g. first click the STATE column and then the CITY column) - open the FORM window, close it and see what happens to the table's sort - it has changed on you :(
Posté le 29 novembre 2016 - 09:47
Hi Scott, as an example, if you have a table with customer names and the customer number as a unique identifier then we return from the Form to the Table with the customer numer and TableSelectPlus(..) the Table to that customer number.

If Form and Table are on different windows, you can call the Form with a customer-ID as a parameter for modification and no customer-ID / customer-ID = 0 for adding a new customer. The Form itself returns a customer-ID when closed which is the customer ID to select in the calling Table. When having mixed uses of Tables and Forms, means that those windows are either not called or a returned customer-ID is not expected then just use a global variable for that purpose.
Posté le 29 novembre 2016 - 17:41
Hi Guenter - thank you, as always, for great advice.

I think I understand what you are describing and will give it a try tonight when I sit down at the keyboard. I remember having this same problem when I was using WD19... I've always used the default PCSoft RAD pattern to generate the generic application and was surprised that the table's sort status wasn't preserved by default when a form window is called - and when the form window is closed and you return focus back to the Table window the sort order status wasn't restored..

:)
Posté le 30 novembre 2016 - 05:03
Hi Guenter,

I got it to work! I changed the RAD-generated code within the MODIFY button on the Table Window to the following code:

IF TableSelect(TABLE_VidTrak)=-1 THEN RETURN

// Grab the unique identifier so we can reposition the table bar when the Form window is closed
gnUniqueID = VidTrak.VidTrakID

// Open the Form window to edit the record
Open(WIN_Form_VidTrak)

// Refresh the table so the edited record is displayed within the table
TableDisplay(TABLE_VidTrak)

// Repositions the bar of the table on the computer that was viewed - modified
// Seek out the saved identifier number in the table
NSubscript = TableSeek(COL_VidTrakID,gnUniqueID)

// Reposition the highlight bar on the saved identifier numbr
TableSelectPlus(TABLE_VidTrak,NSubscript)


The sort orders on the calling Table aren't disturbed when the Form window is closed and the highlight bar is repositioned on the edited record.

Thank you VERY much for your invaluable assistance!
Posté le 30 novembre 2016 - 08:26
Hi Scott, you're welcome!
Posté le 02 décembre 2016 - 05:44
I spoke prematurely; the previous code didn't preserve the AAF sort order. After many failed attempts I did get this code to work every single time - even when I sorted on multiple columns via AAF:

*-- start
// Grab the unique identifier so we can reposition the table bar when the Form window is closed
gnUniqueID = VidTrak.VidTrakID

// Open the Form window to edit the record currently selected in the table
Open(WIN_Form_VidTrak)

// The form window is now closed and data likely modified
// Repositions the bar of the table on the computer that was viewed - modified
// Seek out the saved identifier number in the table
NSubscript = TableSeek(COL_VidTrakID,gnUniqueID)

// Reposition the highlight bar on the saved identifier numbr
TableSelectPlus(TABLE_VidTrak,NSubscript)

// Refresh the TABLE with the modified information without disturbing AAF sorting
SetFocus(COL_Moviename) // without resetting the focus to the first column of the column the form window will
// keep reopening endlessly
SendKey("{ENTER}") // refreshes the table to display the modified data
SendKey("{ECHAP}") // without sending an ESC key into the buffer the form window will keep reopening
// endlessly if the MODIFY button was clicked; this wasn't required if the table
// was left clicked with the mouse however
*----

This code was added to the MODIFY button located on the WIN_TABLE window.
Posté le 02 décembre 2016 - 08:38
Hi Scott, my code looks a bit different

// ---- in " FOCUS gain of Table_ARTIKEL "
// Refresh table data?
IF FOCUS = False THEN // FOCUS is a boolean variable to prevent from running this routine
// Iconize(""); Maximize("") // <= this is for maximizing the MDI-Window in parent window
FOCUS = True
// Setze ausgewählte Zeile auf neuen Datensatz!
IF NEW_ART_NUM > 0 THEN // NEW_ART_NUM is the global variable
MyPosition = TableSeek(Table.ART_NUM,NEW_ART_NUM,True)
TableSelectPlus(Table,MyPosition)
NEW_ART_NUM = 0
END
END
Refresh()