<p>For the second part of your question, look into <a href="https://docs.craftcms.com/v3/extend/element-types.html#sources" rel="nofollow noreferrer">Element Sources</a>. You <em>might</em> be able to pull off  something fancy in a module, where certain users have access to different sources.</p>
<p>For the first part of your question, look into the <code>EVENT_REGISTER_TABLE_ATTRIBUTES</code> and <code>EVENT_SET_TABLE_ATTRIBUTE_HTML</code> events. Here is a rough example of how it will look...</p>
<pre class="lang-php prettyprint-override"><code>// Add index table attributes
Event::on(
    Entry::class,
    Element::EVENT_REGISTER_TABLE_ATTRIBUTES,
    static function(RegisterElementTableAttributesEvent $event) {

        $event-&gt;tableAttributes['computedColumn'] = ['label' =&gt; 'Computed Column'];
        
    }
);

// Modify index table display values
Event::on(
    Entry::class,
    Element::EVENT_SET_TABLE_ATTRIBUTE_HTML,
    static function(SetElementTableAttributeHtmlEvent $event) {

        /** @var Entry $entry */
        $entry = $event-&gt;sender;

        switch ($event-&gt;attribute) {
            case 'computedColumn': // How to identify a computed column
                $event-&gt;html = 'any valid HTML';
                break;
            case 'field:101': // How to identify a normal field
                $event-&gt;html = 'whatever you want it to be';
                break;
        }
        
    }
);
</code></pre>

CC BY-SA 4.0
2020-08-04T17:23:58.313Z
2020-08-04T17:23:58.313Z
Lindsey D
<p>I'm working on a custom Craft 3 site, and I need to be able to configure the element indexes within the control panel for a few of my custom EntryTypes. There's two particular things I'd like to control (which may merit two separate answers):</p>
<ul>
<li>I'd like to be add custom columns to the table. These columns do <em>not</em> correspond to fields on the Entry, but they're more of a &quot;computed property&quot; if that makes sense.</li>
<li>I'd also like to modify the query that is ran for fetching those entries. In my particular case, some entries should not show up based on which user is logged in, and some custom business logic.</li>
</ul>
<p>Is there a way to do this? My current investigation with <code>ElementIndexesController::actionGetElements</code> (the API call that the CP appears to be making) hasn't panned out: I don't see any global events or view hooks that I could wire into.</p>

<craft3><index>
Custom CP Element Indexes
# Custom CP Element Indexes

(Asked by: username_0 on 2020-08-04)

I'm working on a custom Craft 3 site, and I need to be able to configure the element indexes within the control panel for a few of my custom EntryTypes. There's two particular things I'd like to control (which may merit two separate answers):

* I'd like to be add custom columns to the table. These columns do *not* correspond to fields on the Entry, but they're more of a "computed property" if that makes sense.
* I'd also like to modify the query that is ran for fetching those entries. In my particular case, some entries should not show up based on which user is logged in, and some custom business logic.

Is there a way to do this? My current investigation with `ElementIndexesController::actionGetElements` (the API call that the CP appears to be making) hasn't panned out: I don't see any global events or view hooks that I could wire into.

**Tags:** craft3, index


---

## 1 answers

### Answer by username_1 on 2020-08-04. Score: 3

For the second part of your question, look into Element Sources. You might be able to pull off  something fancy in a module, where certain users have access to different sources.
For the first part of your question, look into the EVENT_REGISTER_TABLE_ATTRIBUTES and EVENT_SET_TABLE_ATTRIBUTE_HTML events. Here is a rough example of how it will look...
// Add index table attributes
Event::on(
    Entry::class,
    Element::EVENT_REGISTER_TABLE_ATTRIBUTES,
    static function(RegisterElementTableAttributesEvent $event) {

        $event->tableAttributes['computedColumn'] = ['label' => 'Computed Column'];
        
    }
);

// Modify index table display values
Event::on(
    Entry::class,
    Element::EVENT_SET_TABLE_ATTRIBUTE_HTML,
    static function(SetElementTableAttributeHtmlEvent $event) {

        /** @var Entry $entry */
        $entry = $event->sender;

        switch ($event->attribute) {
            case 'computedColumn': // How to identify a computed column
                $event->html = 'any valid HTML';
                break;
            case 'field:101': // How to identify a normal field
                $event->html = 'whatever you want it to be';
                break;
        }
        
    }
);


---

