Add ability to set the default orderBy in nested element indexes #16236
-
We may be missing something but there doesn't appear to be a way to set the default orderBy within nested element? (We're using the We've defined The only way that I can see of setting a default sort order is via the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for pointing this out. Craft doesn’t have any built-in embedded element indexes that aren’t user-sortable, so this was overlooked. I just added support for setting a return $nestedElementManager->getIndexHtml($owner, [
'defaultSort' => 'attributeName',
// ...
]); It will use the sort direction specified by the sort option’s return $nestedElementManager->getIndexHtml($owner, [
'defaultSort' => ['attributeName', 'desc'],
// ...
]); |
Beta Was this translation helpful? Give feedback.
Thanks for pointing this out. Craft doesn’t have any built-in embedded element indexes that aren’t user-sortable, so this was overlooked.
I just added support for setting a
defaultSort
key on the$config
array when callingcraft\elements\NestedElementManager::getIndexHtml()
for Craft 5.6 (f613051), which you can set to any sortable attribute name supported by your element type’sdefineSortOptions()
method.It will use the sort direction specified by the sort option’s
defaultDir
value (asc
by default). Or you can pass an array which also includes the sort direction.