Back to home page
Il Jester
My little dream is in developing

DM Table

DM Table is not a real plugin, but a class for creating tables. It is a table generator, customizable and suitable for any PHP project. Being a generic class, it is cross-script, so it can be adapted and used on different types of content platform (CMS).

However, the package also includes DM_Table_WP, which is a class prepared specifically for WordPress. DM_Table WP is not an extension of DM_Table, but uses a DM_Table instance.

Preliminary note: all past values ​​should be sanitized and escaped

DM_Table basic usage

First of all, it is necessary to establish where the class is located. We use require or better, require_once:

After that, we create an instance:

Base url

We define the base url, and that is the link that points to our file where we have instantiated the class or is localized your table (eg example.php).


We set sortable select, based on values if you want:


To build search action.

The same explanations apply for sortable, with the due differences in the example, in particular with regards to $args where only one argument is passed with an array as a value.


With filters, we get results based on the established conditions.

Filters can be more than one. For this reason, the first argument of setFilters will be an array of inputs. As an example. Note that $args argument is moved into the inputs array. In the example, we have two filters: by “color” and by “city”.

Important, the “filter” and “input” keys must be called proper “filter” and “input”!


In the table, we need a select for actions. There he is!

The same explanations given for sortable apply.


This is necessary to choose limit items per page. This, if you have a huge amount of data to display in the table.

As you can see the method is the same as those already seen.

Prepare data

Now we need to prepare our query, filtering, action and/or order the data based on the selections seen above.

DM_Table offers us several public properties to do this:

After filtering our query, with result we need to prepare the paging. In this way we will also get the paging values ​​(offset and limit) that will be applied to our query.

A this point, we retrieve the public properties for limit and offset:

Note. As it emerges, we have two properties that have a similar value: $instance->perpage and $instance->limit. In fact they are interchangeable. The first was designed for convenience, because is the result of action perpage and would set “limit” in setPerpage, to get $instance->limit.

At this point, we can conclude the filtering of our query with the properties $limit and $offset. The results will be used to build data table.


Before, we create columns. It is very simply. Is an array:

Table Data

The query result can be an array of objects to be extracted with a while or foreach loop.

Table Set

Now we have all the elements to set up the table.

The table is complete with minimal requirements. To view it:

Inner Row (optional)

If you want, you can insert a innered row in the table. Using this method, after DM_Table::setTable():


For more details, customizations, passable arguments or values, and much more, see the class DM_Table.

For WordPress is available in the package the class DM_Table_WP.

Demo   Download   Donate