Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: 1 [2]
  Reply  |  Print  
Author Topic: Questions on the dynamic array sort  (Read 19279 times)
Reuben B.
Four Js
Posts: 1062


« Reply #15 on: September 12, 2018, 12:53:47 am »

Hello Reuben,

Quote
Also when the user reset sort fields to “defaults” there was no way to detect that and reset the internal array.

I interpreted that to mean ON SORT was not triggered when the user clicked on 'Reset to Defaults' or 'Reset Sort Order', which I could see that that might be something we might miss,  but a quick test suggests that we do cover that possibility and ON SORT is triggered when they are clicked.


In reference to the Quote and your response, this was around attempting to have the screen sort be cumulative by exiting the DISPLAY ARRAY each time ON SORT is triggered after the initial entry.   The ON SORT fires each time sort field is changed or reset.  My reference is that you do not know that user has chosen to reset the sort order to the default versus they just selected another column to sort by.   Example,  default sort order is column 1,  ON SORT is trigger first time DISPLAY ARRAY is hit so exit from DISPLAY ARRAY and order internal array to match user setting and reenter DISPLAY ARAAY.  Do not exit from ON SORT after this initial exit until user selects a column to sort by.  User now selects column 2.  exits loop to sort internal array for column, renters display array,  user selects another column 3 to sort by, exits loop to sort internal array, renters display array, etc,  By exiting loop and reentering each time gives the screen sort the effect of being cumulative.  The issue doing this is when the user clicks on “Reset Sort Order” it “looks” the same to ON SORT as just sorting by another column so array is not really reset to initial sort order it just orders “cumulatively” on this column.   This is what I mean by no way to detect the “reset” versus just another column being selected for cumulative ordering.   
As an aside, there is a feature request for being able to select multiple fields to sort by for display arrays (cumulative) FGL-01477.  There is also an old forum thread “Shocked by ARRAY sort behavior” that is about INPUT ARRAY but hits on DISPLAY ARRAY as well.



Keith,

Thanks for explanation.  I don't think we can expect Reset Sort Order to be able to distinguish between when you exit the array and re-enter, versus a genuine new array.  I would think the best solution would involve not having the hack of re-exiting the array, and re-entering it. 

Re multi-column sort, have you seen this https://github.com/FourjsGenero/fgl_multicolumnsortdialog

Reuben


Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Rene S.
Four Js
Posts: 111


« Reply #16 on: September 12, 2018, 09:13:22 am »

Is this thread a request/reminder for FGL-1477 "Multiple column ordering (sort) in DISPLAY ARRAY" (created 9 years 8 months ago?

A table can be sorted by multiple columns. The sort algorithm is stable. Example: Sorting interactively (by clicking the sort icon in the header of the table-view) first by "gender" then  by "name" produces the same visual result as sorting the table by "ORDER BY name, gender".

The problem is: when entering the dialog again then the "sort history" is lost, the table is sorted only by the last criteria.

We should distinguish 2 scenarios
a) redisplay the table in the same process (the dialog runs in a loop, the dialog is called more then once in the same program).
b) display the table in a new process (after restarting the program)

In case of a) a fix is relatively easy. The runtime can store and reapply the "sort history".
In case of b) a fix is heavy: the fix requires modifications in the runtime and any client.

My instinct: case b) is not relevant.

@all: you should really have a look at Reuben's "Multi Column Sort" at https://github.com/FourjsGenero/fgl_multicolumnsortdialog. Nice and simple code. (BTW: covers case a)
Candy M.
Posts: 139


« Reply #17 on: September 12, 2018, 03:58:27 pm »

Quote
Is this thread a request/reminder for FGL-1477 "Multiple column ordering (sort) in DISPLAY ARRAY" (created 9 years 8 months ago?

I opened this thread as to figure out how the dynamic sort worked.   Back in 2013, we had implemented our own sort of an array to match the visual sort of the screen array.   After the user exits the display array, we would call our sort to sort the program array according to the last column chosen by examining sortType and sortColumn in the DOM tree.   The dialog would be exited before we do this sort.   Our solution has worked fine until last week when one of our customers has a large list of items and the sort was too slow.   So that is when I started investigating the dynamic sort array and I was trying to understand the documentation in order to possibly implement it.   The problem is that we do have customers still on a Centos 5 version, so the highest version we could upgrade them to is a 2.50 version.   2.50 is the lowest version we maintain in our code but 2.50 does not have the dynamic sort.   Reuben said in a previous post that it would not be back ported so I solved our issue by re-coding our sort (which was a bubble sort :-)) to a Quick sort yesterday (using your clue that you were using qsort.   If I was going to need to rewrite my sort, I wanted to see which one the dynamic sort was using).   So I did that and our large list of 26,000+ items now sorts in less than a second.  I will be implementing and testing in our main code base today  (I've already tested a small test on a couple customers servers and it appears to be working nicely).   I will only need to change 3 functions I believe.    We needed to solve this issue immediately and looking at all the options this is the path I took.   I'm don't know that we have need to this request.   The documentation could be clearer as to when the dynamic sort should be executed (in the ON SORT clause or after DIALOG exited).   So I'm all good on our end as we solved our issue by rewriting our sort.

Candy
Candy M.
Posts: 139


« Reply #18 on: September 14, 2018, 08:52:41 pm »

Hello Reuben,
Quote
I created the following example https://github.com/FourjsGenero/ex_browseviewsort which is my interpretation of problem you are trying to solve, and how you can use ON SORT, array.sort(), DIALOG. arrayToVisualIndex() to apply the build-in sort from a DISPLAY ARRAY to the 4gl array
Thank you for doing this.   I believe I understand what you are doing here.   We don't need to keep track on which columns are clicked in the ON SORT clause.   This method will always keep the program array in synch with what was clicked on the table column headers.   

I've been able to implement it on an in-house application, our support system, which uses 3.10.

I do have one comment.
Code
  1. BEFORE DISPLAY
  2.            -- Populate sort_idx with current sorted position
  3.            FOR i = 1 TO arr.getLength()
  4.                LET arr[i].sort_idx = DIALOG.arrayToVisualIndex("scr",i)
  5.            END FOR

Does the for loop need to be in the BEFORE DISPLAY?   I think if a column is already sorted, when you enter the DISPLAY ARRAY, the ON SORT will be called.

Thanks again for taking the time to code this example.    I'll probably be able to implement it in our main application, using our own sort which can run in 2.50.
And the arrays will be much more in synch.

Candy
Reuben B.
Four Js
Posts: 1062


« Reply #19 on: September 15, 2018, 01:56:28 am »

Quote
Does the for loop need to be in the BEFORE DISPLAY?   I think if a column is already sorted, when you enter the DISPLAY ARRAY, the ON SORT will be called.

I think you are right.  I wasn't seeing that but then realised I have stored settings disabled on my GDC.

Reuben

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Pages: 1 [2]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines