<p>I don't believe that there is a <em>recommended</em> way to do this, so I'll attempt to answer this question as best I can. </p>

<p>By using an element type, you will be able to use the element index layout for free, with very little setup. That will give you access to native sorting and searching (filtering), along with a bunch of other things such as grouping, statuses, table and thumbnail views, etc. Creating your element type template is as simple as including the following 3 lines:</p>

<pre><code>{% extends "_layouts/elementindex" %}
{% set title = "ElementName"|t %}
{% set elementType = 'PluginName_ElementName' %}
</code></pre>

<p>There is not way that I know of to natively allow sorting of a table without using an element type and it doesn't look like <a href="https://github.com/pixelandtonic/Garnish/tree/master/Source/classes" rel="nofollow">Garnish</a> offers this functionality.</p>

<p>So I guess the <em>only</em> way at present to make this work with JavaScript is to use an external library such as <a href="http://tablesorter.com/docs/" rel="nofollow">tablesorter</a> or as you mentioned <a href="http://www.datatables.net/" rel="nofollow">DataTables</a>.</p>

CC BY-SA 4.0
2022-06-14T06:47:06.650Z
Any news to this during these 7 years? I got the design down by adding the `data` class to the table-element, but I cannot find out how to reuse the sorting functionality.
PWL
CC BY-SA 3.0
2015-03-30T13:10:29.613Z
2015-03-30T13:10:29.613Z
Ben Croker
<p>Whats the recommended way to have javascript based filtering and sort table views in a plugin tab?  </p>

<p>Is is possible to use garnish to do that or should we be looking at external libraries like:</p>

<p><a href="http://www.datatables.net/" rel="noreferrer">http://www.datatables.net/</a></p>

CC BY-SA 3.0
2014-12-16T04:02:44.693Z
I'm interested in this as well. We're you able to find anything?
nateiler
CC BY-SA 3.0
2014-12-16T04:06:47.383Z
Seems like the only way to use the built in sorting is by using an element type.
Keith Mancuso
<plugin-development><garnish>
Filtering and sorting lists in a plugin
# Filtering and sorting lists in a plugin

(Asked by: username_0 on 2014-09-29)

Whats the recommended way to have javascript based filtering and sort table views in a plugin tab?

Is is possible to use garnish to do that or should we be looking at external libraries like:

<http://www.datatables.net/>

**Tags:** plugin-development, garnish

> **Comments:**
> **username_1**: I'm interested in this as well. We're you able to find anything?  
> **username_0**: Seems like the only way to use the built in sorting is by using an element type.  

---

## 1 answers

### Answer by username_2 on 2015-03-30. Score: 3 | Accepted answer

I don't believe that there is a recommended way to do this, so I'll attempt to answer this question as best I can. 
By using an element type, you will be able to use the element index layout for free, with very little setup. That will give you access to native sorting and searching (filtering), along with a bunch of other things such as grouping, statuses, table and thumbnail views, etc. Creating your element type template is as simple as including the following 3 lines:
{% extends "_layouts/elementindex" %}
{% set title = "ElementName"|t %}
{% set elementType = 'PluginName_ElementName' %}

There is not way that I know of to natively allow sorting of a table without using an element type and it doesn't look like Garnish offers this functionality.
So I guess the only way at present to make this work with JavaScript is to use an external library such as tablesorter or as you mentioned DataTables.

> **Comments:**
> **username_3**: Any news to this during these 7 years? I got the design down by adding the `data` class to the table-element, but I cannot find out how to reuse the sorting functionality.  

---

