Я впервые работал с некоторыми примерами в книге, используя грушу ... пока что это выглядит довольно круто, но у меня небольшая проблема, когда мне нужно настроить форматирование одного конкретного столбца таблица, сгенерированная из Structures_DataGrid & HTML_Table - в частности, она мне нужна, чтобы не переносить текст в ячейке на дефисе - что, я думаю, я мог бы сделать, используя «nowrap» и html / css - но пока я не вижу, как передать такого рода форматирование просто один столбец в таблице ...
Есть предложения?
Добавлен исходный код ниже:
<?php
// Include the DB access credentials
require 'dbcred.php';
// Include the PEAR Structures_DataGrid class
require 'Structures/DataGrid.php';
// instantiate grid for 10 records per page
$datagrid = new Structures_DataGrid(10);
// Define our Datasource options, in this case PDO MySQL
$options = array('dsn' => "mysql://$user:$password@$db_host/$db_name");
// Define the Query
$sql = "SELECT * FROM contact_info";
// Bind the Query to our Datagrid
$bind = $datagrid->bind($sql, $options);
// Test for Errors
if (PEAR::isError($bind))
{
/*error_log('DataGrid Error: '. $bind->getMessage());
$gridsource = 'Foo';*/
echo $bind -> getMessage();
}
else
{
// Define our Column labels, using a 'column' => 'Label' format
$columns = array(
'title' => 'Title',
'first_name' => 'First Name',
'mid_init' => 'Mid. Init.',
'last_name' => 'Last Name',
'suffix' => 'Suffix',
'street_address' => 'Street Address',
'city' => 'City',
'state_prov' => 'State/Province',
'post_code' => 'Postal Code',
'phone_pri' => 'Phone (Pri)',
'phone_alt' => 'Phone (Alt)',
'email' => 'E-Mail',
);
$datagrid->generateColumns($columns);
// Some more options, for our renderer
$renderer_options = array(
'sortIconASC' => '⇑',
'sortIconDESC' => '⇓',
'headerAttributes' => array('bgcolor' => '#E3E3E3'),
'evenRowAttributes' => array('bgcolor' => '#A6A6A6'),
);
$datagrid->setRendererOptions($renderer_options);
// Add some final attributes to our table
$renderer = $datagrid->getRenderer();
$renderer->setTableAttribute('cellspacing', 0);
$renderer->setTableAttribute('cellpadding', 5);
$renderer->setTableAttribute('border', 1);
// Render the table, be sure to check for errors
$gridbody = $datagrid->getOutput();
if (PEAR::isError($gridbody))
{
error_log('DataGrid render error: ' . $gridbody->getMessage());
$gridbody = '';
}
// Finally, render the pager, again checking for errors
$gridpager = $datagrid->getOutput(DATAGRID_RENDER_PAGER);
if (PEAR::isError($gridpager))
{
error_log('DataGrid render error: ' . $gridpager->getMessage());
$gridpager = '';
}
$gridsource = $gridbody . $gridpager;
}
?>
<!DOCTYPE html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PEAR::Structures_DataGrid</title>
<meta http-equiv="Content-type"
content="text/html; charset=iso-8859-1" />
<style type="text/css">
body {
font-family: Tahoma, Arial, Helvetica, sans-serif;
font-size: 11px;
}
h1 {
font-size: 1.2em;
color: navy
}
th {
white-space: no-wrap;
}
</style>
</head>
<body>
<h1>PEAR::Structures_DataGrid</h1>
<?php echo $gridsource ?>
</body>
</html>