<p>You can take a look at this question <a href="https://craftcms.stackexchange.com/questions/5029/set-custom-sort-order-for-index-pages-in-the-cp">Set custom sort order for index pages in the CP?</a> for Craft 2 and see <a href="https://docs.craftcms.com/v3/updating-plugins.html#modifyentrysortableattributes-modifycategorysortableattributes-modifyassetsortableattributes-modifyusersortableattributes" rel="nofollow noreferrer">updating Plugins for Craft 3</a> in the docs</p>

<pre class="lang-php prettyprint-override"><code>// Old:
public function modifyEntrySortableAttributes(&amp;$attributes)
{
    $attributes['id'] = Craft::t('ID');
}

// New:
use craft\base\Element;
use craft\elements\Entry;
use craft\events\RegisterElementSortOptionsEvent;
use yii\base\Event;

Event::on(Entry::class, Element::EVENT_REGISTER_SORT_OPTIONS, function(RegisterElementSortOptionsEvent $event) {
    $event-&gt;sortOptions['id'] = \Craft::t('app', 'ID');
});
</code></pre>

<p>Keep in mind your field must be sortable via SQL</p>

CC BY-SA 4.0
2018-06-20T02:50:22.030Z
In this way, this **sort option type** will be applied to all the sections. What if some of the sections don't have this **sort option type**?
yu xia
CC BY-SA 4.0
2018-06-21T08:08:07.440Z
@yuxia `$event->sender` contains the element so you can check it's section and entry type
Robin Schambach
CC BY-SA 4.0
2018-06-22T00:47:54.367Z
Unfortunately, for me it's not working. I dd out the **$event**:
`
RegisterElementSortOptionsEvent {#4331 ▼
  +sortOptions: array:8 [▶]
  +name: "registerSortOptions"
  +sender: null
  +handled: false
  +data: null
}
`
yu xia
CC BY-SA 4.0
2018-06-19T07:40:32.393Z
2018-06-26T19:45:14.730Z
2018-06-26T19:45:14.730Z
Robin Schambach
<p>I would like to add a custom field for order by on the drop down menu on admin CP. How can I do it, is there any event for this in Craft 3? </p>

<p>It is a plugin related question, we are using custom plugin to customize our application</p>

<plugin-development>
How can I add custom field to order by on the admin CP in Craft 3?
# How can I add custom field to order by on the admin CP in Craft 3?

(Asked by: username_0 on 2018-06-19)

I would like to add a custom field for order by on the drop down menu on admin CP. How can I do it, is there any event for this in Craft 3?

It is a plugin related question, we are using custom plugin to customize our application

**Tags:** plugin-development

---

## 1 answers

### Answer by username_1 on 2018-06-19. Score: 3 | Accepted answer

You can take a look at this question Set custom sort order for index pages in the CP? for Craft 2 and see updating Plugins for Craft 3 in the docs
// Old:
public function modifyEntrySortableAttributes(&$attributes)
{
    $attributes['id'] = Craft::t('ID');
}

// New:
use craft\base\Element;
use craft\elements\Entry;
use craft\events\RegisterElementSortOptionsEvent;
use yii\base\Event;

Event::on(Entry::class, Element::EVENT_REGISTER_SORT_OPTIONS, function(RegisterElementSortOptionsEvent $event) {
    $event->sortOptions['id'] = \Craft::t('app', 'ID');
});

Keep in mind your field must be sortable via SQL

> **Comments:**
> **username_2**: In this way, this **sort option type** will be applied to all the sections. What if some of the sections don't have this **sort option type**?  
> **username_1**: @yuxia `$event->sender` contains the element so you can check it's section and entry type  
> **username_2**: Unfortunately, for me it's not working. I dd out the **$event**: ` RegisterElementSortOptionsEvent {#4331 ▼   +sortOptions: array:8 [▶]   +name: "registerSortOptions"   +sender: null   +handled: false   +data: null } `  

---

