<p>I finally found the answer to this question.</p>

<p>From <a href="https://craftcms.com/classreference/elementtypes/BaseElementType#defineAvailableTableAttributes-detail">BaseElementType defineAvailableTableAttributes() docs</a>, </p>

<blockquote>
  <p>The <em>first</em> item that this array returns will just identify the database
  column name, and the table column’s header, but will not have any
  effect on what shows up in the table’s body. That’s because the first
  column is reserved for displaying whatever your element model’s
  <em>__toString()</em> method returns (the string representation of the element).</p>
</blockquote>

<p>So all you need to do is add a <em>__toString()</em> method in your model and return the string representation of your element:</p>

<p>For example:</p>

<pre><code>public function __toString()
{
   return $this-&gt;id;
}
</code></pre>

<p>Result:</p>

<p><a href="https://i.sstatic.net/Vf1DD.png"><img src="https://i.sstatic.net/Vf1DD.png" alt="enter image description here"></a></p>

CC BY-SA 3.0
2016-11-23T06:35:00.403Z
2016-11-23T06:35:00.403Z
Anya Dit
<p>As a workaround you could hide the default title column and add your own:</p>

<pre><code>public function modifyEntryTableAttributes(&amp;$attributes, $source)
{
    if ($source == 'section:2')
    {
        $attributes = array();
        $attributes['myOwnTitle'] = Craft::t('Title');
        $attributes['uri'] = Craft::t('URI');
        $attributes['postDate'] = Craft::t('Post Date');
        $attributes['expiryDate'] = Craft::t('Expiry Date');
    }
}

public function getEntryTableAttributeHtml(EntryModel $entry, $attribute)
{
    switch ($attribute)
    {
        case 'myOwnTitle':
        {
            return 'blabla';
        }

        ...
    }
}
</code></pre>

CC BY-SA 3.0
2015-08-31T12:33:47.320Z
2015-08-31T12:33:47.320Z
carlcs
<p>I want to change the title in the index of an custom element.</p>

<pre><code>public function getTableAttributeHtml(BaseElementModel $element, $attribute)
{
    switch ($attribute)
    {
        case 'title' :
        {
            return $element-&gt;attribute . 'blabla';
        }

        ...
    }
}
</code></pre>

<p>But whatever I try, the title field didn't change. Other fields are no problem.
How can i do this?</p>

<plugin-development><elementtype><index>
Change custom element Index title via getTableAttributeHtml?
# Change custom element Index title via getTableAttributeHtml?

(Asked by: username_0 on 2015-08-28)

I want to change the title in the index of an custom element.
public function getTableAttributeHtml(BaseElementModel $element, $attribute)
{
    switch ($attribute)
    {
        case 'title' :
        {
            return $element->attribute . 'blabla';
        }

        ...
    }
}

But whatever I try, the title field didn't change. Other fields are no problem.
How can i do this?

**Tags:** plugin-development, elementtype, index

---

## 2 answers

### Answer by username_1 on 2016-11-23. Score: 5

I finally found the answer to this question.
From BaseElementType defineAvailableTableAttributes() docs, 

The first item that this array returns will just identify the database
  column name, and the table column’s header, but will not have any
  effect on what shows up in the table’s body. That’s because the first
  column is reserved for displaying whatever your element model’s
  __toString() method returns (the string representation of the element).

So all you need to do is add a __toString() method in your model and return the string representation of your element:
For example:
public function __toString()
{
   return $this->id;
}

Result:


---

### Answer by username_2 on 2015-08-31. Score: 1

As a workaround you could hide the default title column and add your own:
public function modifyEntryTableAttributes(&$attributes, $source)
{
    if ($source == 'section:2')
    {
        $attributes = array();
        $attributes['myOwnTitle'] = Craft::t('Title');
        $attributes['uri'] = Craft::t('URI');
        $attributes['postDate'] = Craft::t('Post Date');
        $attributes['expiryDate'] = Craft::t('Expiry Date');
    }
}

public function getEntryTableAttributeHtml(EntryModel $entry, $attribute)
{
    switch ($attribute)
    {
        case 'myOwnTitle':
        {
            return 'blabla';
        }

        ...
    }
}


---

