Skip to content

Generating Tables with HTMLTable

Darryl Hein edited this page Dec 30, 2013 · 2 revisions
<?php

$table = new HTMLTable(array(
	'table_attributes' => array(
		'class' => 'xm_content',
	),
	'heading' => array(
		'', // for action links
		'Name',
		'Phone Number',
	),
));

foreach ($records as $record) {
	$record->set_mode('view');

	$row_num = $table->add_row(array(
		HTML::anchor('/edit/' . $record->pk(), HTML::icon('edit')),
		$record->name,
		$record->get_field('phone'),
	));

	if ( ! $record->active_flag) {
		$table->set_row_class($row_num, 'inactive');
	}
}

$html = $table->get_html();
// or
echo $table;