curvegrid / multibaas-for-google-sheets

MIT License
8 stars 4 forks source link

MBCUSTOMQUERY results should have a consistent column order by selector index not alias #40

Open daenamkim opened 3 years ago

daenamkim commented 3 years ago

MBCUSTOMQUERY result columns are generated in order by alias of selector but it should be by index of selector to keep a consistent column order no matter what alias is.

alias: account, index: 0

Screen Shot 2020-12-02 at 13 11 28

alias: sender, index: 0

Screen Shot 2020-12-02 at 13 11 48

This part might need be fixed. https://github.com/curvegrid/multibaas-for-google-sheets/blob/6518546c6aa060ce84b6c37878ed051c52179bd0/src/library/Util.js#L107-L118

daenamkim commented 3 years ago

@shoenseiwaso

I additionally found a backend API changes columns order according to alias (high priority) or name but not an input index in MBQUERY(). It reads presets from the backend so I might need to change backend for this. What do you think?

MBCUSTOMQUERY() can set an input index in the spreadsheet so the order can be changed no matter what the backend returns.

If I set amount's alias to "total" from event query in the MultiBaas then the column will be switched. image

shoenseiwaso commented 3 years ago

The back-end returns results in both cases as an array of objects (map). The elements (key/value pairs) are unordered by definition, even if the back-end always appears to return them in a consistent order, we cannot rely on this.

My suggestion for now is to use the default order for MBQUERY(), and for the spreadsheet plugin to re-order into the same order as the custom query for MBCUSTOMQUERY().

In the future (separate issue, low priority) for MBQUERY() we can first lookup the Event Query definition and then order by that order, but that is too much work for too little benefit at this point, I think.