Nested Lists View

Hi, I'm trying to create a nested lists view for the following case.

I've a table with a list of items.
Clicking on a row, it opens a sidebar containers where the structure is the following:

  • A (container)
    -- B1 (ListView1)
    --- C1 (ListView2)
    --- C2 (ListView2)
    -- B2 (ListView1)
    --- D1 (ListView2)
    -- B3 (ListView1)
    --- E1 (ListView2)
    --- E2 (ListView2)
    --- E3 (ListView2)

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)).

Thanks

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:

Order 1

  • Warehouse A
    -- Item 1
    -- Item 2
    -- Item 3
    -- Item 4
  • Warehouse B
    -- Item 5
  • Warehouse C
    -- Item 6
    -- Item 7

What I've been able to create is:

Order 1

  • Warehouse A
    -- Item 1
    -- Item 2
    -- empty
    -- empty
  • Warehouse B
    -- Item 2
  • Warehouse C
    -- Item 3
    -- Item 2

OR

Order 1

  • Warehouse A
    -- Item 1
    -- Item 2
    -- Item 3
    -- Item 4
  • Warehouse B
    -- Item 1
    -- Item 2
  • Warehouse C
    -- Item 1
    -- Item 2

Thanks for posting the question!

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.

You can read more in our official guide.

Thank you for your reply.

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()

Thanks

Any feedback on the previous question?
I'm stuck on it :frowning:

I'm not understanding which format is expecting from the query:

If in a JS transform I do:

const arr1 = [['dog', 'cat', 'frog'],['pippo', 'pluto', 'amen']]
return arr1  

with
{{ transformer2.value[0][i]}}

it prints

dog
cat
frog

Instead, if in an SQL query I put

select '[["dog", "cat", "frog"],["pippo", "pluto", "amen"]]' as a

with

{{query7.data.a[0][i]}}

it prints
[
[
"

I understand that the query is not returning the array properly
image
but I don't know how to make it works.

@number15 Can you try this?

{{ eval(query7.data.a[0])[0][i] }}


While query7.data.a[0] is equivalent to transformer2.value it is a string and can be evaluated as an array as I've done. Does that work?

yes, it works! :blush:

So to print the info like this (considering that every item has additional info):

  • Warehouse A
    -- Item 1
    -- Item 2
    -- Item 3
    -- Item 4
  • Warehouse B
    -- Item 1
    -- Item 2

Can I just return a rows like in this format

warehouse A | [["item1_attribute1", "item1_attribute2", "item1_attribute3"],["item2_attribute1", "item2_attribute2", "item2_attribute3"]]....
warehouse B | [["item1_attribute1", "item1_attribute2"],["item2_attribute1", "item2_attribute2"]]...

Is it correct or is there any downside to consider (like maybe a limit in the string length?) and so is it better to use any alternative way?

Thanks!

I don't think I have the context needed to advise on a most efficient data structure for your requirements, but I think that should work.

Unfortunately it's still not working as I need.

I tried
{{ eval(query2.data.item_id[0])[ri[0]][i] }}
but it doesn't print the correct info in each listview.

I still think that i didn't understand which should be the correct format because with the format.

@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).

Thanks

Ok, it seems that i've found how to do it.

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.