The TableField module implements a custom field that allows users to attach tabular data to any content page/entity type. Data can be entered into the table manually or imported via a CSV upload. The amount of rows and columns can be configured globally on an entity type or on a per node basis. The field can also be configured to allow users to export the tabular data as a CSV file.
In this tutorial, we’ll create a Company content type and use this module to display opening times.
Setting up the module is very easy as there are no dependencies. Simply download TableField and install the module.
Create Company Content Type
To demonstrate how to use this module, we’ll create a content type called Company and we’ll attach a “Table Field” to the content type that will allow site editors to add opening times.
1. Go to Structure -> Content types (admin/structure/types) and click on “Add content type”.
2. Add Company to the Name field and click on “Save and add fields”.
3. Create an “Opening times” field using the settings defined in Table 1-0.
Table 1-0. Define an “Opening times” field
|Field type||Table Field|
4. Check both “Allow users to export table data as CSV” and “Lock table field defaults from further edits during node add/edit.” checkboxes and click on “Save field settings”.
5. Scroll down to the “Default value” field-set and click on the “Change number of rows/columns.” field-set.
6. For this tutorial, change the “How many Columns” to 3 and “How many Rows” to 8 and then click on “Rebuild Table”.
7. Enter in some default values. For this tutorial, I entered in the following.
8. Scroll to the bottom and click on “Save settings”.
TableField in Action
Now that we have configured our content type and field, let’s now see it in action.
1. Go to Content -> “Add content” and click on Company (node/add/company).
2. Enter in a title and if you scroll down you should see the “Opening times”.
If you click on the “Change number of rows/columns.” field-set, you can change the amount of columns and rows for this specific node page. From the “Import from CSV” field-set, you can upload data via a CSV file.
If you want to test out this functionality, save the CSV data below into a file and upload the file using the “File upload” field.
Days,To,From Monday,9am,5pm Tuesday,9am,5pm Wednesday,9am,5pm Thursday,9am,9pm Friday,9am,5pm Saturday,9am,4pm Sunday,Closed,Closed
3. Once you have saved the node form, you should be able to see the data within a table.
If you want to allow users to export the tabular data, then you’ll have to assign the “Export Tablefield Data as CSV” permission to a role.
If you have any questions, please leave a comment.