Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-20T02:50:22.030Z
Answers.Text: 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**?
Answers.UserDisplayName: yu xia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-21T08:08:07.440Z
Answers.Text: @yuxia `$event->sender` contains the element so you can check it's section and entry type
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-22T00:47:54.367Z
Answers.Text: 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
  }
  `
Answers.UserDisplayName: yu xia
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-19T07:40:32.393Z
Answers.LastActivityDate: 2018-06-26T19:45:14.730Z
Answers.LastEditDate: 2018-06-26T19:45:14.730Z
Answers.UserDisplayName: Robin Schambach
Body: <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>
  
Tags: <plugin-development>
Title: How can I add custom field to order by on the admin CP in Craft 3?
ThreadText: # 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?](https://craftcms.stackexchange.com/questions/5029/set-custom-sort-order-for-index-pages-in-the-cp) for Craft 2 and see [updating Plugins for Craft 3](https://docs.craftcms.com/v3/updating-plugins.html#modifyentrysortableattributes-modifycategorysortableattributes-modifyassetsortableattributes-modifyusersortableattributes) in the docs
  
  ```php
  // 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**: @username_2 `$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 } `  
  
  ---
  
  