There are 2 main ways to create editable wpDataTables:
- Create tables manually (see details here) or import the table data from Excel or CSV (see details here)
- Create a MySQL based wpDataTable and configure it as editable.
Tables created manually with Table Constructor are back-end editable by default; to allow front-end editing you would need just open “Editing” tab in table configuration settings and click “Allow editing” option and click “Apply” button (the ID column and the table name will be pre-configured for this type of tables by default).
Then your front-end users would already be able to edit the table data.
For creating MySQL-based editable tables which you already prepared in your MySQL DB server the algorithm is a little bit more complicated.
First you would need to create a table on MySQL side, and a MySQL-query based wpDataTable; the steps for this are described in this tutorial.
Then, when the table is created, you would need to got to “Editing” tab in table configuration settings and click “Allow editing” button like from the example above.
Our plugin will try to guess the “MySQL table name for editing” and the “ID column for editing” (if the column name is “id” or “ID” or similar it will usually guess correctly).
In some cases it is necessary to provide the name for “MySQL table name for editing” and the “ID column for editing” for a couple of reasons: first of all it is not always possible to parse it from the query; and secondly – sometimes you would like to send the changes to a different table rather from the one used in the query. After you define these settings don’t forget to press the “Apply” button.
When the table is saved, and inserted in the post or page, the look of the table in the front-end is slightly different from a usual non-editable table. You can notice that there are three new buttons in the TableTools section of the table (or just three if you didn’t enable TableTools for this wpDataTable).
Manual tables will be always editable on the table configuration page and you will always see these three buttons independently from “Allow editing” feature.
Also it becomes possible to select a row in the table by clicking it, it will become highlighted (you can change the highlight color along with other table colors in the table settings page).
To make editing possible we need to choose editor input types for the columns that we want to allow users to edit. For this we need to open column configuration panel (by clicking on “Column settings” button or by clicking “Complete column list” button from where we can open column configuration) for each column that you want to make editable. Then we have to make a selection in “Editor input type” dropdown under “Editing” tab. Possible input types are fully explained in this section.
When the editor input types are chosen and saved, you can go to table front-end (open the post or page where you inserted the table) once again, choose any row, and click “Edit“; or click “New” to create a new entry. You will see an editor popup. The popup is responsive, so it will work correctly on mobile and tablet devices as well.
- In the left side of the editor popup you will see the names of the columns.
- On the right side of the editor popup you will see the editor inputs for the cells.
- On the bottom side you will see the control and navigation buttons.Cancel – discards all changes and closes the editor popup.
- << Prev – selects the previous row of the table (if not the first one is selected), if necessary switches to the previous page, and puts the data from this row in the front-end editor. Changes will be discarded, if they weren’t saved.
- Next >> – selects the next row of the table (if not the last one is selected), if necessary switches the table to the next page, and puts the data from this row to the front-end editor inputs. Changes will be discarded, if they weren’t saved.
- Apply and add new – saves the data from the editor in the current row, doesn’t close the popup but opens a new editor with the blank input fields.
- OK – saves the data from the editor in the current row, and closes the editor popup.
- Right top “X” button is equal to “Cancel” – discards all unsaved changes and closes the popup
When you click “Save” or “OK” data is first validated and then sent to MySQL engine. If the data is invalid, or MySQL returns an error you will see an error message which tells you which field is problematic and what to change.
While the data saving is in progress you will see an overlay that indicates that the process is going on in the background. If the data is sent fine you will see a success message.
Please read the next documentation section to see full details on how to configure columns in the editable table correctly.
- Only one MySQL table can be edited at a time. Queries from multiple tables with joins cannot be used for editable feature, since SQL UPDATE and INSERT statements are generated automatically, and for now there is no way to update multiple tables – but we are working on this.
- Only MySQL tables or tables created with “Create a table manually” and “Create a table by importing data from data source” options of “Create a Table” page can be edited.
- Server-side processing MUST be turned on for front-end editing – but it will turn on automatically if you forget to enable it.
- MySQL Views cannot be edited properly – only one of the underlying tables can in case you pass the proper ID.