【问题标题】:How to add a tfoot row to table generated with codeigniter table class如何将 tfoot 行添加到使用 codeigniter 表类生成的表中
【发布时间】:2017-07-19 16:06:29
【问题描述】:

我想在 CI 表类生成的表中添加页脚行。有一些类可以扩展表类并添加此功能。如果可用,我更愿意使用本机功能而不扩展表类。

CI表类中可以吗?

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    我最终在表格下方放置了一个具有类似格式的 div,以提供页脚行的错觉。希望将来 table 类将包含 tfoot 功能。

    我知道扩展类会将此功能添加到 CI 表类中。

    【讨论】:

      【解决方案2】:

      这是一个老问题,但我刚刚遇到了同样的问题,这是修改后的表格库,允许表格页脚

      https://github.com/rhspeer/TableWithTableFooter

      【讨论】:

        【解决方案3】:

        我确实扩展了表格类,我还将模板设置为默认使用 jquery ui,并且与上面的示例不同,我不重新创建不需要更新的基本方法。

        在应用程序/库中添加一个名为 MY_table.php 的文件

        <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
        class MY_Table extends CI_Table{
        var $footer = array();
        function __construct()
        {
            parent::__construct();
            $this->template = array(
                'table_open'            => '<table class="ui-corner-top ui-widget" >',
        
                'thead_open'            => '<thead class="ui-widget-header">',
                'thead_close'           => '</thead>',
                'heading_row_start'     => '<tr>',
                'heading_row_end'       => '</tr>',
                'heading_cell_start'    => '<th>',
                'heading_cell_end'      => '</th>',
        
                'tbody_open'            => '<tbody class="ui-widget-content">',
                'tbody_close'           => '</tbody>',
        
                'row_start'             => '<tr class="table_row_odd">',
                'row_end'               => '</tr>',
                'cell_start'            => '<td>',
                'cell_end'              => '</td>',
        
                'row_alt_start'         => '<tr class="table_row_even">',
                'row_alt_end'           => '</tr>',
                'cell_alt_start'        => '<td>',
                'cell_alt_end'          => '</td>',
        
                'tfoot_open'            => '<tfoot class="ui-widget-header ui-priority-secondary">',
                'footer_row_start'      => '<tr>',
                'footer_row_end'        => '</tr>',
                'footer_cell_start'     => '<th>',
                'footer_cell_end'       => '</th>',
                'tfoot_close'           => '</tfoot>',
        
                'table_close'           => '</table>'
            );
            $this->empty_cells = '&nbsp;';
        }
        function set_template($template)
        {
            // extends the normal method so that only the required elements have to be entered.  the remainder stay as defaults.
            if ( ! is_array($template))
            {
                return FALSE;
            }
            else
            {
                foreach($template as $param => $value)
                {
                    $this->template[$param] = $value;
                }
            }
        
        }
        function set_footer()
        {
            $args = func_get_args();
            $this->footer = $this->_prep_args($args);
        }
        function clear()
        {
            $this->footer = array();
            parent::clear();
        }
        // extend the generate table method.  just adds the bit in to handle tfoot.
        
        function generate($table_data = NULL)
        {
            // The table data can optionally be passed to this function
            // either as a database result object or an array
            if ( ! is_null($table_data))
            {
                if (is_object($table_data))
                {
                    $this->_set_from_object($table_data);
                }
                elseif (is_array($table_data))
                {
                    $set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE;
                    $this->_set_from_array($table_data, $set_heading);
                }
            }
        
            // Is there anything to display?  No?  Smite them!
            if (count($this->heading) == 0 AND count($this->rows) == 0)
            {
                return 'Undefined table data';
            }
        
            // Compile and validate the template date
            $this->_compile_template();
        
            // set a custom cell manipulation function to a locally scoped variable so its callable
            $function = $this->function;
        
            // Build the table!
        
            $out = $this->template['table_open'];
            $out .= $this->newline;
        
            // Add any caption here
            if ($this->caption)
            {
                $out .= $this->newline;
                $out .= '<caption>' . $this->caption . '</caption>';
                $out .= $this->newline;
            }
        
            // Is there a table heading to display?
        
            if (count($this->heading) > 0)
            {
                $out .= $this->template['thead_open'];
                $out .= $this->newline;
                $out .= $this->template['heading_row_start'];
                $out .= $this->newline;
        
                foreach ($this->heading as $heading)
                {
                    $temp = $this->template['heading_cell_start'];
        
                    foreach ($heading as $key => $val)
                    {
                        if ($key != 'data')
                        {
                            $temp = str_replace('<th', "<th $key='$val'", $temp);
                        }
                    }
        
                    $out .= $temp;
                    $out .= isset($heading['data']) ? $heading['data'] : '';
                    $out .= $this->template['heading_cell_end'];
                }
        
                $out .= $this->template['heading_row_end'];
                $out .= $this->newline;
                $out .= $this->template['thead_close'];
                $out .= $this->newline;
            }
            if (count($this->footer) > 0)
            {
                $out .= $this->template['tfoot_open'];
                $out .= $this->newline;
                $out .= $this->template['footer_row_start'];
                $out .= $this->newline;
        
                foreach ($this->footer as $footer)
                {
                    $temp = $this->template['footer_cell_start'];
        
                    foreach ($footer as $key => $val)
                    {
                        if ($key != 'data')
                        {
                            $temp = str_replace('<th', "<th $key='$val'", $temp);
                        }
                    }
        
                    $out .= $temp;
                    $out .= isset($footer['data']) ? $footer['data'] : '';
                    $out .= $this->template['footer_cell_end'];
                }
        
                $out .= $this->template['footer_row_end'];
                $out .= $this->newline;
                $out .= $this->template['tfoot_close'];
                $out .= $this->newline;
            }
        
            // Build the table rows
            if (count($this->rows) > 0)
            {
                $out .= $this->template['tbody_open'];
                $out .= $this->newline;
        
                $i = 1;
                foreach ($this->rows as $row)
                {
                    if ( ! is_array($row))
                    {
                        break;
                    }
        
                    // We use modulus to alternate the row colors
                    $name = (fmod($i++, 2)) ? '' : 'alt_';
        
                    $out .= $this->template['row_'.$name.'start'];
                    $out .= $this->newline;
        
                    foreach ($row as $cell)
                    {
                        $temp = $this->template['cell_'.$name.'start'];
        
                        foreach ($cell as $key => $val)
                        {
                            if ($key != 'data')
                            {
                                $temp = str_replace('<td', "<td $key='$val'", $temp);
                            }
                        }
        
                        $cell = isset($cell['data']) ? $cell['data'] : '';
                        $out .= $temp;
        
                        if ($cell === "" OR $cell === NULL)
                        {
                            $out .= $this->empty_cells;
                        }
                        else
                        {
                            if ($function !== FALSE && is_callable($function))
                            {
                                $out .= call_user_func($function, $cell);
                            }
                            else
                            {
                                $out .= $cell;
                            }
                        }
        
                        $out .= $this->template['cell_'.$name.'end'];
                    }
        
                    $out .= $this->template['row_'.$name.'end'];
                    $out .= $this->newline;
                }
        
                $out .= $this->template['tbody_close'];
                $out .= $this->newline;
            }
        
        
            $out .= $this->template['table_close'];
        
            // Clear table class properties before generating the table
            $this->clear();
            return $out;
        }
        

        }

        【讨论】:

          【解决方案4】:

          我想这就是你要搜索的内容

          https://github.com/EllisLab/CodeIgniter/wiki/Table

          【讨论】:

          • 我已经通过它扩展基类对此进行了研究,我正在寻找一种不扩展基表类的方法。
          • 我不认为 codeigniter 在 CI HTML Table Class 中提供页脚
          • 我试图避免这种反应:),但看起来我必须扩展表类。但还是有希望的......
          【解决方案5】:

          不需要扩展表库,你可以使用set_template函数,传递数组模板。

          【讨论】:

            猜你喜欢
            • 2013-05-24
            • 2022-06-15
            • 2020-11-21
            • 2017-02-03
            • 2014-07-08
            • 1970-01-01
            • 2021-03-31
            • 2021-10-10
            • 2014-03-17
            相关资源
            最近更新 更多