TableField
Provides a flexible field type for storing and displaying tabular data with support for CSV import/export, drag-and-drop row reordering, and customizable headers.
tablefield
Install
composer require 'drupal/tablefield:^3.0'
composer require 'drupal/tablefield:8.x-2.5'
Overview
TableField is a comprehensive field type module that enables content authors to input, manage, and display tabular data directly within Drupal entities. It provides a user-friendly widget interface where users can define table dimensions, enter cell values, and optionally specify table captions for accessibility.
The module supports multiple input methods including direct cell editing, CSV file import, and copy-paste functionality from spreadsheet applications like Excel. Tables can be dynamically resized by adjusting the number of rows and columns, and rows can be reordered via drag-and-drop. The field supports both plain text and filtered text (with text format selection) for cell content.
For display, the formatter offers options to designate the first row and/or first column as table headers. An optional CSV export feature allows users with appropriate permissions to download table data. The module also provides a computed property for Search API integration, enabling full-text search of table contents.
Features
- Custom field type for storing tabular data in a serialized blob format with support for captions and text formats
- Flexible widget with configurable input types (textfield or textarea) for cell data entry
- Dynamic table rebuilding allowing users to change the number of rows and columns via AJAX
- Drag-and-drop row reordering with weight-based sorting
- CSV file import with automatic encoding detection (UTF-8, ISO-8859-1, WINDOWS-1251)
- Copy and paste import functionality supporting various delimiters (TAB, comma, semicolon, pipe, plus, colon)
- CSV export functionality for downloading table data
- Table caption support for improved accessibility and screen reader compatibility
- Cell locking feature to prevent editing of default values (useful for fixed headers)
- Text format support allowing filtered text with user-selectable input formats
- Configurable empty rules to determine when a tablefield should be considered empty
- Integration with responsive_tables_filter module for responsive table display
- Computed table_value property for Search API indexing
- Granular permissions for export, import, rebuild, paste, and row addition operations
Use Cases
Product Specifications Table
Create a field on product content types to display technical specifications in a structured table format. Set the first row as the header with specification names (e.g., 'Dimension', 'Weight', 'Material') and allow content editors to fill in values for each row. Enable CSV export so customers can download specifications.
Pricing Matrix
Build a pricing table with fixed headers using the lock_values feature. Set default values for column headers (e.g., 'Plan', 'Monthly', 'Annual') and lock them so editors can only modify the pricing values. Use the first column as a row header for plan names.
Schedule or Timetable
Create event schedules or class timetables using TableField. Enable the textarea input type for cells that need longer content. Use drag-and-drop to easily reorder rows when schedule changes occur.
Data Import from Spreadsheets
Allow content editors to quickly populate tables by copying data from Excel or Google Sheets using the paste functionality. Select TAB as the column separator for seamless import from spreadsheet applications.
Comparison Charts
Build feature comparison tables with the cellspan submodule to create merged header cells spanning multiple columns. Use #colspan# to group related features under category headers.
Form Builder with Required Fields
Use the tablefield_required submodule to create data entry tables where specific rows or columns must be filled out, such as mandatory contact information rows in a registration form.
Tips
- Use the 'Lock cell default values' setting to create tables with fixed headers that content editors cannot modify
- Enable 'Display first column as a table header' in the formatter for tables where the first column contains row labels
- When importing from Excel, use TAB as the column separator in the paste import dialog
- Set meaningful default row and column counts in the global settings to reduce the need for table rebuilding
- Use the table caption field to provide context for screen readers and improve accessibility
- Consider enabling text format selection (filtered text) only when HTML formatting is needed in cells, as it adds complexity
- For large data sets, allow CSV import permission to enable efficient bulk data entry
Technical Details
Admin Pages 1
/admin/config/content/tablefield
Configure global default settings for all TableField instances including the CSV separator character and default table dimensions.
Permissions 6
Hooks 1
hook_tablefield_encodings_alter
Allows modules to alter the list of character encodings supported for CSV import. By default, TableField supports UTF-8, ISO-8859-1, and WINDOWS-1251.
Troubleshooting 5
Ensure the source data uses UTF-8 encoding. Check if the CSV separator in module settings matches your spreadsheet application's expected delimiter.
Rows containing locked cells cannot be reordered. Remove the lock_values setting or ensure the row has no locked cells to enable drag-and-drop.
The import functionality requires both the 'import tablefield' permission and the restrict_import field setting to be properly configured. Grant the permission to the appropriate roles.
Select the correct column separator that matches your source data. Data copied from Excel typically uses TAB separators.
Check the empty_rules settings. If 'ignore_table_structure' is unchecked, a table with different dimensions than the default is considered non-empty even without cell content.
Security Notes 3
- The module sanitizes cell content through Drupal's text format system when cell_processing is enabled
- CSV export requires both the field-level 'export' setting and the 'export tablefield' permission
- Import and rebuild operations can be restricted to specific permissions to prevent unauthorized data modification