代码之家  ›  专栏  ›  技术社区  ›  memilanuk

格式化用php/pear结构生成的表\u datagrid&html_table

  •  0
  • memilanuk  · 技术社区  · 15 年前

    我第一次在一本书中用梨做例子…到目前为止,这看起来很酷,但我遇到了一个小问题,我需要调整从结构\datagrid&html\u表生成的表中某一列的格式-特别是我需要它不要在连字符处将文本包装在单元格中-我认为我可以使用“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' => '&uArr;',
            'sortIconDESC' => '&dArr;',
            '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>
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   SCBoy    15 年前

    不知道梨是什么,但是: 您可以在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>
    

    这使得第一列的背景为绿色。

    推荐文章