<p>You weren’t overlooking anything, we were :)</p>

<p>We just released <a href="http://buildwithcraft.com/updates#build2616" rel="nofollow">Craft 2.3.2616</a> with four new hooks:</p>

<ul>
<li><a href="http://buildwithcraft.com/docs/plugins/hooks-reference#modifyEntrySortableAttributes" rel="nofollow">modifyEntrySortableAttributes</a></li>
<li><a href="http://buildwithcraft.com/docs/plugins/hooks-reference#modifyCategorySortableAttributes" rel="nofollow">modifyCategorySortableAttributes</a></li>
<li><a href="http://buildwithcraft.com/docs/plugins/hooks-reference#modifyAssetSortableAttributes" rel="nofollow">modifyAssetSortableAttributes</a></li>
<li><a href="http://buildwithcraft.com/docs/plugins/hooks-reference#modifyUserSortableAttributes" rel="nofollow">modifyUserSortableAttributes</a></li>
</ul>

<p>That should do the trick for you.</p>

CC BY-SA 3.0
2014-12-04T09:10:20.780Z
Yes, that's great! Thanks Brandon. Would it be greedy if I asked for those hooks to also support a source parameter? I also wondered how to define a secondary sort key for each attribute, is this possible?
carlcs
CC BY-SA 3.0
2014-12-04T10:45:35.517Z
@carlcs The source is not known when element types' defineSortableAttributes() is called; it's only called once, on the initial page load, and the options don't change when changing sources. (The only exception to that is, the JS will add the "Structure" option in dynamically when a structured source is selected.) Not sure what you mean by a "secondary source key for each attribute"?
Brandon Kelly
CC BY-SA 3.0
2014-12-04T10:54:33.437Z
I meant a secondary key that you can sort by, if the primary values were the same (e.g. sort by lightswitch field and then by datetime field).
carlcs
CC BY-SA 3.0
2014-12-04T11:01:49.573Z
Thanks so far, but I hope you find a working solution to define sortableAttributes per source. I think this is essential to the whole functionality (I don't want the Client to be able to sort the "Blog" structure by "Opening Time" for example).
carlcs
CC BY-SA 3.0
2014-12-04T12:43:31.317Z
@carlcs The keys you add will be passed directly into the `order` parameter, so you can juts throw a comma in the array key.
Brandon Kelly
CC BY-SA 3.0
2014-12-04T13:05:31.897Z
I tried this, but it doesn't work. It doesn't throw any PHP errors, but I can't click the option in the dropdown. You mean like this `$attributes['exhibitionPlace,releaseDate desc']`, right? The same string works in an ElementCriteriaModel in my template though!
carlcs
CC BY-SA 3.0
2014-12-04T13:42:55.447Z
@carlcs Yes that’s what I meant, but there were a couple bugs preventing that form working as expected. Just fixed that for the next release.
Brandon Kelly
CC BY-SA 3.0
2014-12-03T22:30:35.613Z
2014-12-03T22:30:35.613Z
Brandon Kelly
<p>Good chance this is more of a feature request than a question you can help out. But as I am new to Craft plugin development and might oversee something I ask it anyways:</p>

<p>Now that it is possible to customize the index pages in the CP using the plugin hooks <a href="http://buildwithcraft.com/docs/plugins/hooks-reference#modifyEntryTableAttributes" rel="nofollow noreferrer"><code>modifyEntryTableAttributes</code></a> and <a href="http://buildwithcraft.com/docs/plugins/hooks-reference#getEntryTableAttributeHtml" rel="nofollow noreferrer"><code>getEntryTableAttributeHtml</code></a>, what do I have to do to make my custom columns appear in the sort order dropdown / make the entries sortable by my new columns?</p>

<plugin-development><control-panel>
Set custom sort order for index pages in the CP?
# Set custom sort order for index pages in the CP?

(Asked by: username_0 on 2014-12-02)

Good chance this is more of a feature request than a question you can help out. But as I am new to Craft plugin development and might oversee something I ask it anyways:

Now that it is possible to customize the index pages in the CP using the plugin hooks [`modifyEntryTableAttributes`](http://buildwithcraft.com/docs/plugins/hooks-reference#modifyEntryTableAttributes) and [`getEntryTableAttributeHtml`](http://buildwithcraft.com/docs/plugins/hooks-reference#getEntryTableAttributeHtml), what do I have to do to make my custom columns appear in the sort order dropdown / make the entries sortable by my new columns?

**Tags:** plugin-development, control-panel

---

## 1 answers

### Answer by username_1 on 2014-12-03. Score: 2 | Accepted answer

You weren’t overlooking anything, we were :)

We just released [Craft 2.3.2616](http://buildwithcraft.com/updates#build2616) with four new hooks:

* [modifyEntrySortableAttributes](http://buildwithcraft.com/docs/plugins/hooks-reference#modifyEntrySortableAttributes)
* [modifyCategorySortableAttributes](http://buildwithcraft.com/docs/plugins/hooks-reference#modifyCategorySortableAttributes)
* [modifyAssetSortableAttributes](http://buildwithcraft.com/docs/plugins/hooks-reference#modifyAssetSortableAttributes)
* [modifyUserSortableAttributes](http://buildwithcraft.com/docs/plugins/hooks-reference#modifyUserSortableAttributes)

That should do the trick for you.

> **Comments:**
> **username_0**: Yes, that's great! Thanks Brandon. Would it be greedy if I asked for those hooks to also support a source parameter? I also wondered how to define a secondary sort key for each attribute, is this possible?  
> **username_1**: @carlcs The source is not known when element types' defineSortableAttributes() is called; it's only called once, on the initial page load, and the options don't change when changing sources. (The only exception to that is, the JS will add the "Structure" option in dynamically when a structured source is selected.) Not sure what you mean by a "secondary source key for each attribute"?  
> **username_0**: I meant a secondary key that you can sort by, if the primary values were the same (e.g. sort by lightswitch field and then by datetime field).  
> **username_0**: Thanks so far, but I hope you find a working solution to define sortableAttributes per source. I think this is essential to the whole functionality (I don't want the Client to be able to sort the "Blog" structure by "Opening Time" for example).  
> **username_1**: @carlcs The keys you add will be passed directly into the `order` parameter, so you can juts throw a comma in the array key.  
> **username_0**: I tried this, but it doesn't work. It doesn't throw any PHP errors, but I can't click the option in the dropdown. You mean like this `$attributes['exhibitionPlace,releaseDate desc']`, right? The same string works in an ElementCriteriaModel in my template though!  
> **username_1**: @carlcs Yes that’s what I meant, but there were a couple bugs preventing that form working as expected. Just fixed that for the next release.  

---

