2

I have a grid datawindow with some headers and columns in Powerbuilder 10.5.

Using the pfc all my headers have identical names as the columns and end with _t as indicated.

At runtime when I click on some headers the rows are not sorted correctly.
After the first click the rows are sorted in ascending order.
After the second click the rows are sorted in descending order.
After the third click the rows are sorted in ascending order as the first click.
After the fourth click the rows seem to be sorted in descending order but the first row is not the same as in the second click sorting.

Though for some headers sorting works correctly. What might be the problem?

Alex
  • 207
  • 1
  • 2
  • 15
  • Is there something in common for those which do not work? Are they computed columns? Is there some expression used in a column which would change things as the row number changes? – Matt Balent Jun 20 '14 at 12:04
  • I can't find anything in common. For example one of these is a date or a document id. But a description is ok. After the `idw_Requestor.Sort()` in `n_cst_dwsrv_sort` the initial rows are not the same. The call of `GroupCalc()` after that does not seem to change anything. – Alex Jun 20 '14 at 12:17
  • You could try saving the dw as an excel spreadsheet while in the debugger after each header click {something like dw.saveas('c:\temp\dw.xls',XLS!,true) } and then examine the contents in Excel to determine if any data changed. – Matt Balent Jun 20 '14 at 16:18

1 Answers1

1

When you sort on a column that has more than one row with the same value, the order of the rows with the same value is undefined. In technical terms the sort in the DataWindow is not a Stable Sort.

Hugh Brackett
  • 2,706
  • 14
  • 21
  • Thanks. I also had a feeling that could be the case. It seems to choose randomly for example the rows with the same document id. But why does this not happen in the ascending order? – Alex Jun 21 '14 at 09:26
  • It's hard to say without knowing what sort algorithm(s) the DataWindow uses. Efficient sorting algorithms sometimes detect that the data is sorted or nearly so and use a different strategy. Some algorithms that work by chopping up the data use some randomness to try to avoid worst-case behavior. – Hugh Brackett Jun 24 '14 at 00:05