Skip to content

Add ability to set the default orderBy in nested element indexes #16236

Closed Answered by brandonkelly
ryansupercool asked this question in Ideas
Discussion options

You must be logged in to vote

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 calling craft\elements\NestedElementManager::getIndexHtml() for Craft 5.6 (f613051), which you can set to any sortable attribute name supported by your element type’s defineSortOptions() method.

return $nestedElementManager->getIndexHtml($owner, [
    'defaultSort' => 'attributeName',
    // ...
]);

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.

return $nestedEleme…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ryansupercool
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants