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:
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityWhats 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:
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.
data
class to the table-element, but I cannot find out how to reuse the sorting functionality.