I've created the query, using the selectedRow.data.id to count the rows for ListView1 and another one to return the proper rows and this is working.
Now i've the problem with the query to count the rows ListView2 and the one to return the proper rows. The keys to be used here are a value in ListView1.
I'm not understanding if this query should be trigger multiple times based on the different items in ListView1 (eg. one time for B1 key and another time B2 key) or just one time with both keys (eg. id IN (B1 key, B2 key)).
I did some progress.
I've been able to print the correct number of ListView2 inside the ListView1 adding a count in the query for ListView1 and referring to it ({{query.data.num_of_items[i]}}).
Now I'm struggling to print the correct info in each ListView2.
For example:
{{query2.data.item_id}} returns all the ids
{{query2.data.item_id[ri[i]]}} prints the correct item_id only for the first item in each ListView2. The second item has always the same id and from the third no id
{{query2.data.item_id[i]}} prints the correct item_id for all the items in the first ListView2 but uses the same ids also for the items in the other ListView2.
Here a better example of what I'm trying to create:
To use nested list view, it may be easier to change your query data to be a multi-dimensional array, in this case, a 2 dimensional array, since you are using 2 levels of nested list view. For example, you can make {{ query2.data.item_id[1][2] }} return the id for the third item in the second ListView2. If you can't do that in the backend, you may want to use a transformer to do so in retool.
After that, note that ri refers to the index in every levels of the nested list view, while iis the index in the closet list view, so you want to use ri[0] to refer to the index in ListView1, rather than using ri[i]. So for example if you tweak the data as specified above, you can access the data with query.data.item_id[ri[0]][ri[1]]. In this case i is equivalent to ri[1] so you can also write this as query.data.item_id[ri[0]][i]. Note that ri[i] typically doesn't make sense, because the length of ri is determined by the nested levels of list views, while the possible values of iis determined by the instances count of the closest list view.
Sorry, can you please give me an example of the rows format needs to be returned from the query with my example data? (I'm advanced user of SQL, but I'm very bad in coding)
Unfortunately, our current version of MySQL doesn't support functions like JSON_ARRAYAGG()
@yyjhao can you please help me with the format to be returned by the query?
I'm thinking if you meant that I should have 1 query already returning all the info (warehouses and items) instead of 2 queries (one per warehouses and one per items).
It needs to return just one row with all the arrays, following the same order of the warehouses.
So the format is:
[["item1_warehouseA_attribute1", "item2_warehouseA_attribute1", "item3_warehouseA_attribute1"],["item4_warehouseB_attribute1"], .... ] | [["item1_warehouseA_attribute2", "item2_warehouseA_attribute2", "item3_warehouseA_attribute2"],["item4_warehouseB_attribute2"], .... ] | ....
In this way
{{ eval(query2.data.item_id[0])[ri[0]][i] }}
returns the correct results.