Is it possible to sort the output of treeList?
$orgUnits = $this->OrganizationalUnits->find('treeList', [
'keyPath' => 'id',
'valuePath' => 'name_en',
'spacer' => '-'])
->order(['name_en']);
Under the same level, they're not coming out sorted. In my test case, I have 3 entries: one starting with b, t and a respectively.
CodePudding user response:
You would have to override the order set by the finder, as it defaults to ordering on lft
, which is a unique value, so no sub-ordering by other fields would be possible.
You can do so via the order()
method's second argument:
order(['name_en'], true)
or
order(['name_en'], \Cake\ORM\Query::OVERWRITE)
See also