The problem is sorting. I need sort by order, which I have on kanban board, from first header to last. .sort(t => t.line); - do nothing, the order remains in alphabet.
Asking for help. I have not found enough information to solve it on one’s own.
You’ve got a few issues with your query, which counter each other to some extent.
First of all, when you do .groupBy you change the data available. You introduce a key variable which holds the value of the t.header in your case, and all the other variables are grouped together and “hidden” in the rows object/list. This means that when you in the next line try to sort on t.line there isn’t any t.line to sort on, as it is hidden within the rows list.
One way to counter this is to do the .sort(t => t.line) in front of the .groupBy. The group by operations preserves the original order as long as it can, as least that’s my experience so far. This mean that if the list is sorted before grouping, it’ll preserve that order, but the items are split out in the various group in the same order as they were originally (if that make sense).
Does that construct on result.forEach() actually do anything useful? In most context, doing a .forEach() should change the main object, but you’ve entered a grey area when dereferencing sub-object and so on… In any case, I’d say it looks cleaner if you do a .mutate within the original list instead of that construct.
Trying to fix all of these issues, but not having anything relevant test data to test it on, I’m currently at a query looking like: