Body: <p>I'm on CraftCMS 4.6.1</p>
  <p>This element uses a custom table and manages quote requests. The problem I'm having is that I cannot seem to dictate the name of the header column used for the primary key <code>id</code> which is the &quot;link&quot; that you click on the element index page to &quot;edit/process&quot; the request. The platform is forcing the header to be <code>Quote Request</code> which is the output from my <code>displayName()</code> method. When I try to specify an override for the column name in the <code>defineTableAttributes()</code> method as shown below, the column is simpliy duplicated with &quot;ID&quot; header but without links. This duplicated column has all of the desired sorting function but it comes at the cost of a &quot;duplicated column&quot; which I want to avoid.</p>
  <p>In my custom Element Class I have the following setup:</p>
  <p>My display name is set via:</p>
  <pre class="lang-php prettyprint-override"><code>public static function displayName(): string
  {
      return 'Quote Request';
  }
  </code></pre>
  <p>I defined my table attributes like this:</p>
  <pre class="lang-php prettyprint-override"><code>protected static function defineTableAttributes(): array
  {
      return [
          'id' =&gt; 'ID',
          'firstName' =&gt; 'First Name',
          'lastName' =&gt; 'Last Name',
          'company' =&gt; 'Company',
          'sent' =&gt; 'Completed',
          'promoCode' =&gt; 'Promo Code',
          'dateCreated' =&gt; 'Created On',
      ];
  }
  </code></pre>
  <p>I specify my sort options like so:</p>
  <pre class="lang-php prettyprint-override"><code>protected static function defineSortOptions(): array
  {
      return array_merge([
          'id' =&gt; [
              'label' =&gt; 'ID',
              'orderBy' =&gt; 'elements.id',
              'attribute' =&gt; 'id',
              'defaultDir' =&gt; 'desc',
          ]
      ], parent::defineSortOptions());
  }
  </code></pre>
  <p>This results in the column being duplicated, and the duplicate column (without links) allows you to click the header to toggle sort direction, and also works with the sort controls above the table.</p>
  <p>If I remove the <code>'id' =&gt; 'ID',</code> line from the <code>defineTableAttributes()</code> method, the column is no longer duplicated (only the default <code>Quote Request</code> column is present, and you can still use the sort controls above the table to sort the list by that column, but in this case the sort controls panel still refers to the column as &quot;ID&quot; as specified. Furthermore, the directional sort arrow is not added to the first column header like it does with the duplicated column when present.</p>
  <p>Even hovering the first (forced/default) column header does not &quot;highlight&quot; the cell to indicate it is even clickable (because it isn't).</p>
  <p>Here is a screenshot showing what I mean:
  <a href="https://i.sstatic.net/VKPLP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VKPLP.png" alt="enter image description here" /></a></p>
  <p>When I add the ID column back via my <code>defineTableAttributes()</code> method, this is what the duplication looks like and as you can see works as desired, but is now a duplicate column which I do not want:
  <a href="https://i.sstatic.net/nGcan.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nGcan.png" alt="enter image description here" /></a></p>
  <p><strong>The main question:</strong>
  How can I get the main/default column header to say ID instead of &quot;Quote Request&quot; and have all of the normal sorting functionality that the other columns enjoy?</p>
  <p><em>Is changing <code>displayName()</code> my only option for the header column title? Does this not affect anything else? I only want the column header to display ID but I still want this class to be referred to as a &quot;Quote Request&quot; in other contexts...</em></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-08T04:40:26.027Z
Comments.Text: If i understand your question correctly, maybe you can use EVENT_DEFINE_SOURCE_TABLE_ATTRIBUTES event. please read https://github.com/craftcms/cms/discussions/12032
Comments.UserDisplayName: user9975
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-03-08T23:03:48.680Z
Comments.Text: @user9975 I appreciate the attempt at an answer but I don't believe this will help.
Comments.UserDisplayName: Rick Kukiela
Tags: <control-panel><elementtype><sorting>
Title: Custom Element Index ID column missing sorting behavior
ThreadText: # Custom Element Index ID column missing sorting behavior
  
  (Asked by: username_0 on 2024-02-07)
  
  I'm on CraftCMS 4.6.1
  
  This element uses a custom table and manages quote requests. The problem I'm having is that I cannot seem to dictate the name of the header column used for the primary key `id` which is the "link" that you click on the element index page to "edit/process" the request. The platform is forcing the header to be `Quote Request` which is the output from my `displayName()` method. When I try to specify an override for the column name in the `defineTableAttributes()` method as shown below, the column is simpliy duplicated with "ID" header but without links. This duplicated column has all of the desired sorting function but it comes at the cost of a "duplicated column" which I want to avoid.
  
  In my custom Element Class I have the following setup:
  
  My display name is set via:
  
  ```php
  public static function displayName(): string
  {
      return 'Quote Request';
  }
  
  ```
  
  I defined my table attributes like this:
  
  ```php
  protected static function defineTableAttributes(): array
  {
      return [
          'id' => 'ID',
          'firstName' => 'First Name',
          'lastName' => 'Last Name',
          'company' => 'Company',
          'sent' => 'Completed',
          'promoCode' => 'Promo Code',
          'dateCreated' => 'Created On',
      ];
  }
  
  ```
  
  I specify my sort options like so:
  
  ```php
  protected static function defineSortOptions(): array
  {
      return array_merge([
          'id' => [
              'label' => 'ID',
              'orderBy' => 'elements.id',
              'attribute' => 'id',
              'defaultDir' => 'desc',
          ]
      ], parent::defineSortOptions());
  }
  
  ```
  
  This results in the column being duplicated, and the duplicate column (without links) allows you to click the header to toggle sort direction, and also works with the sort controls above the table.
  
  If I remove the `'id' => 'ID',` line from the `defineTableAttributes()` method, the column is no longer duplicated (only the default `Quote Request` column is present, and you can still use the sort controls above the table to sort the list by that column, but in this case the sort controls panel still refers to the column as "ID" as specified. Furthermore, the directional sort arrow is not added to the first column header like it does with the duplicated column when present.
  
  Even hovering the first (forced/default) column header does not "highlight" the cell to indicate it is even clickable (because it isn't).
  
  Here is a screenshot showing what I mean:
  [![enter image description here](https://i.sstatic.net/VKPLP.png)](https://i.sstatic.net/VKPLP.png)
  
  When I add the ID column back via my `defineTableAttributes()` method, this is what the duplication looks like and as you can see works as desired, but is now a duplicate column which I do not want:
  [![enter image description here](https://i.sstatic.net/nGcan.png)](https://i.sstatic.net/nGcan.png)
  
  **The main question:**
  How can I get the main/default column header to say ID instead of "Quote Request" and have all of the normal sorting functionality that the other columns enjoy?
  
  *Is changing `displayName()` my only option for the header column title? Does this not affect anything else? I only want the column header to display ID but I still want this class to be referred to as a "Quote Request" in other contexts...*
  
  **Tags:** control-panel, elementtype, sorting
  
  > **Comments:**
  > **username_1**: If i understand your question correctly, maybe you can use EVENT_DEFINE_SOURCE_TABLE_ATTRIBUTES event. please read https://github.com/craftcms/cms/discussions/12032  
  > **username_0**: @username_1 I appreciate the attempt at an answer but I don't believe this will help.  
  
  ---
  
  ## 0 answers
  
  