Data Table is an addition to the core form API which allows the creation of a datatable field type. A data table is a draggable, sortable, table of data. Not only does it provide a table full of editable data, but also allows the developer to define a custom structure to display the data which taps directly into the form API. For example, rather than showing a grid full of text boxes, the developer can specify any of the normal form API elements to be used instead(ie: checkboxes, select lists, text areas, etc..)
Usage
$form['example'] = array(
'#type' => 'datatable',
'#draggable' => TRUE,
'#limit' => 25, // Use 0 for unlimited
'#structure' => array(
array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => NULL,
),
array(
'#type' => 'select',
'#title' => t('Favorite Color'),
'#default_value' => 'red',
'#options' => array(
'red' => 'Red',
'green' => 'Green',
'blue' => 'Blue'
),
),
array(
'#type' => 'checkbox',
'#title' => t('Likes Cats'),
'#return_value' => 1,
'#default_value' => 0,
)
),
'#value' => array(
array('John Doe', 'green', 0),
array('Lauren Ipsum', 'red', 1),
array('Test', 'blue', 1),
),
);
Sponsorship