Pivot sort rows by first column on each nested level

Hey there guys!
Check this snippet: https://snippet.webix.com/sxo6jjht
As far as I was able to understand - rows order by default depends on items order in data.
How can I have my rows sorted by first column (taking into account nested levels)?
For example in my snippet above the top-most level is “form”. So “Constitutional” should go before “Republic” because “c” goes before “r”.
Next level is “continent”. Here “Africa” should go first, then “Asia” and so on.
Third level is “name”. Here “Argentina” should go first, then “Brazil”, then “Columbia” (because “a” goes before “b” and “c”, then goes “b” and then goes “c”).
Many thanks

@vitaliy_kretsul
https://snippet.webix.com/5vi8z90k

This is perfect, thanks.
One more thing: how can I specify sort order (asc/desc)?

https://docs.webix.com/api__link__ui.datatable_sort.html
you can add “desc” as optional argument.
or multiply return value by -1

For some reason “desc” sort direction doesn’t work for me for numeric values:
https://snippet.webix.com/5s2dpesn
I’ve tried both: “desc” argument and switching -1 with 1 and 1 with -1 in return statements.
Though it works OK for string values.
What am I doing wrong?

Thanks

@vitaliy_kretsul

there is something wrong with displaying rows’ headers.
looks like a bug.

https://snippet.webix.com/vmgkkn4k
check this sample and change “asc” to “desc”.
attention to values.
they must not change (if row ordering is right) but they do.

Yes, I see what you are talking about. But what shell I do about that? I need to be able to sort my rows in descending direction.
Thanks

Hi there @intregal
Any news concerning my request?
Thanks

@vitaliy_kretsul
I hope webix team can help you in this issue.

Hello @vitaliy_kretsul ,

You can sort with any custom sorting rule by API ( that includes sorting by two columns ), there is no default UI to initiate sorting by two columns, though.

It possible to override default single-column sorting behavior, that while only one column is marked as sorting source, it will always include other column in sorting ( user clickes on any column, components sort by that column and by date column for example )

Please check the next snippet, sorting work by all columns. When values are the same they are ordered by the first column (so grid is sorted by selected and first columns )

http://webix.com/snippet/393b48da

Hi there @Nastja
Many thanks for your answer, but it seems there is some small misunderstanding. Your reply doesn’t answer my question at all. This is not what I was asking about. Please, check my comment once again: https://forum.webix.com/discussion/comment/21650/#Comment_21650

The problem is with sorting numeric values by first column (check snippet attached)
Thanks

Hi there @Nastja
Could you please check this thread once again? Back in the days I never received any clarification from you.
So, your last comment seems to be an answer to a different question then mine. I am not interested in sorting by multiple columns.
My only concern is a bug with sorting numeric values in first column.

Hi @vitaliy_kretsul

My only concern is a bug with sorting numeric values in first column.

It’s not actually a bug.
As a complex component, Pivot has two levels of data storage (two instances of DataStore).

One for the raw data - it will be used for data aggregation and has no visual appearance. It is accessible as pivot.data.
The second belongs to the rendered grid and contains the current result of data aggregation (pivot.$$("data").data).
Therefore, sorting (any supported data-related method - add, sort, filter, etc.) in Pivot can be applied to 2 levels of data.

As well as pivot.load() or parse() loads the raw data to the 1st datastore, such methods as pivot.sort() or filter() will be related to it too.
Thus, such sorting will not affect the result of data aggregation directly, but it will change the order of initial data items, so the order of grouped items in the result will be also changed.

To apply any method to the result of calculations displayed in the table, you need to call it from the table API, which is accessible as pivot.$$("data")

The above method of data sorting can be used as follows:

https://snippet.webix.com/w3gt9ryg

Other options (for constant data sorting after applying the new structure) are described in the related discussion.