我在第一次使用梨的书中一直在研究一些例子...到目前为止看起来很酷,但是我有一个小问题,我需要调整一个特定列的格式从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>
答案 0 :(得分:1)
不知道梨是什么,但是: 您可以在html中格式化这样的列:
<table>
<col style="background: green;" />
<col />
<tr>
<td>First TD of first TR</td>
<td>Second TD of first TR</td>
</tr>
<tr>
<td>First TD of second TR</td>
<td>Second TD of second TR</td>
</tr>
</table>
这使第一列的背景变为绿色。