Using TableField in Drupal 7

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.

Getting Started

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.

3. Create an “Opening times” field using the settings defined in Table 1-0.

Table 1-0. Define an “Opening times” field

Option

Value

Label

Opening times

Machine name

field_opening_timesâ€Ž

Field type

Table Field

Widget

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.

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.

About Ivan Zugec

Ivan is the founder of Web Wash and spends most of his time consulting and writing about Drupal. He's been working with Drupal for 10 years and has successfully completed several large Drupal projects in Australia.

Hi. Is it possible to use tablefield with nodeimport module? I don’t see tablefield as target in node import settings althought I’ve inserted it into my content type. Thank you very much for your time!

I wondered if you have tried importing csv data into a tablefield?
I’ve just migrated from 6 to 7 and have found that none of my Tablefiedl data has migrated which appears to be a known bug.
At the moment i am thinking about migrating the data using feeds importer.
Any recommendations? Great tutorial by the way.

Hi,
I would like to display table in template file.
When I use field_get_items(‘node’, $node, ‘field_table_test’)[0][‘value’];

I get output like below:
a:5:{s:7:”caption”;s:25:”Website-Navigationsdaten “;s:7:”rebuild”;a:3:{s:10:”count_cols”;s:1:”3″;s:10:”count_rows”;s:2:”15″;s:7:”rebuild”;s:13:”Rebuild Table”;}s:6:”import”;a:2: {s:5:”row_0″;a:4:{s:5:”col_0″;s:15:”Art der Cookies”;s:5:”col_1″;s:12:”Beschreibung”;s:5:”col_2″;s:41:”Optionen zur Verwaltung der Einstellungen”;s:6:”weight”;s:1:”1″;}s:5:”row_1″;a:4:{s:5:”col_0″;s:22:”Erforderliche Cookies”;s:5:”col_1″;s:800:”deaktivieren..”;s:6:”weight”;s:1:”2″;}s:5:”row_2″;a:4:{s:5:”col_0″;s:0:””;s:5:”col_1″;s:0:””;s:5:”col_2″;s:0:””;s:6:”weight”;s:2:”15″;}}}
Please help me getting it the way it perfectly displays on ontent type without calling it in template file
Thanks a lot