Query - list, spacer for treeList

How do I set a spacer for this list, where do I have groups? There is a spacer option for finder treeList, but I didn’t find anything here. Please advise.

    return $query->find('list', [
        'keyPath' => 'id',
        'groupField' => function($data) {
            return $data->site_name;
        },
        'valueField' => function($data) {
            return $data->node_name;
        },
        'spacer' => '   ',
        'order' => [
            'Navigations.site_id' => 'ASC'
        ],
    ])

What does the result of this look like, and what do you expect it to look like?

This result is:

[
  'Group 1' => [
    (int) 8 => 'About Us',
    (int) 9 => 'Contact',
    (int) 1 => 'Products',
    (int) 2 => 'Category 1',
    (int) 3 => 'Category 2',
    (int) 4 => 'Category 3',
  ],
  'Group 2' => [
    (int) 13 => 'Homepage',
    (int) 10 => 'About Us',
    (int) 11 => 'Contact',
  ],
]

It should be:

[
  'Group 1' => [
    (int) 8 => 'About Us',
    (int) 9 => 'Contact',
    (int) 1 => 'Products',
    (int) 2 => '   Category 1',
    (int) 3 => '   Category 2',
    (int) 4 => '   Category 3',
  ],
  'Group 2' => [
    (int) 13 => 'Homepage',
    (int) 10 => 'About Us',
    (int) 11 => 'Contact',
  ],
]

I’m not clear on how you think it’s supposed to know what should have this added to it and what shouldn’t. You’re explicitly calling list, which does only a single level of the data. treeList does more, because that’s what treeList's purpose is.

And can a treelist result in groups?

I’ve never had a need for treeList, so I can’t speak to that. I know it’s there, and what it’s for, but not the details.

1 Like