1
A
回答
1
我最後決定將具有相似的格式表下一個div提供的footer行的錯覺。希望將來桌子班將包括tfoot功能。
我知道擴展類,它會將此功能添加到CI表類。
0
1
這是一個老問題,但我只是碰到了同樣的問題,這裏的修改表庫,允許表頁腳
+0
好好的努力,將來會用到你的工作。謝謝 –
1
我並擴展表類,我還設置了模板默認使用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 = ' ';
}
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;
}
文件}
0
沒必要延伸表庫,你會使用set_template
功能,通過陣列模板。
相關問題
- 1. 如何將類添加到kramdown生成的內容表中?
- 2. 如何使用動態生成的表動態添加行
- 3. CodeIgniter表類:從生成的單元格添加鏈接
- 4. 使用codeigniter的數據表不會將結果添加到表
- 5. 使用表類codeigniter中的特定行添加類
- 6. KendoUI網格 - 如何添加一個類到生成的表格
- 7. 使用jQuery將raphael生成的圖表添加到文檔中
- 8. 如何將csrf_token添加到動態生成的表單中?
- 9. 如何將數據表添加到動態生成的高圖
- 10. 如何將圖像添加到c3.js生成的圖表
- 11. 如何使用Extjs將行從表單添加到表單中?
- 12. 如何使用lambda將類列表對象添加到類中?
- 13. 如何將類添加到列表中?
- 14. 使用AngularJS將行添加到表單
- 15. Codeigniter將Glyphicon添加到表單按鈕
- 16. 將動態生成的列表添加到新列表中
- 17. 如何將選擇(下拉列表)添加到我生成的表單中?
- 18. 如何使用jQuery將新行添加到指定的表中?
- 19. 如何將行添加到使用jQuery的表中?
- 20. 如何使用javascript將行添加到表格的開頭
- 21. Jekyll \ kramdown - 添加`.table`類生成表格
- 22. 使用「自動生成」字段將數據行添加到數據表中
- 23. 將WebService屬性添加到使用CodeDom生成的類
- 24. 如何將類添加到jQuery數據表中的新行?
- 25. 如何使用jQuery將類添加到列表項目
- 26. VB如何使用迭代將項添加到類列表?
- 27. 如何添加一行到非唯一表類使用jQuery
- 28. Bootstrap將行添加到表
- 29. 將行添加到html表
- 30. 將行添加到表
我已經看過這個擴展基類,我正在尋找一種不擴展基表類的方法。 –
我不認爲codeigniter在CI HTML表中提供頁腳類 –
我試圖避免這種迴應:),但它看起來像我將不得不擴展表類。但還是有希望的...... –