【发布时间】:2011-07-23 21:51:08
【问题描述】:
我正在使用 CI 生成表格
$query = $this->expenses_model->expenses_table();
//gary's code went here
$this->load->library('table');
$tmpl = array ('table_open' => '<table class="table">');
$this->table->set_template($tmpl);
// gary added 'Edit' at end of array
$this->table->set_heading('Date', 'Plant', 'Expense', 'Category', 'Notes');
//when using gary's code, changed $query below to $data
$table['tab'] = $this->table->generate($query);
$this->load->view('vw/exp/expenses_vw', $table, TRUE);
在客户端使用 jQuery DataTables 运行
$(document).ready(function() {
/* Init DataTables */
var oTable = $('.table').dataTable( {
"bJQueryUI": true,
"sScrollX": "",
"bSortClasses": false,
"aaSorting": [[0,'desc']],
"bAutoWidth": true,
"bInfo": true,
"sScrollY": "100%",
"sScrollX": "100%",
"bScrollCollapse": true,
"sPaginationType": "full_numbers",
"bRetrieve": true
} );
} );
问题 #1
数据库中的每条记录都有一个唯一的自动增量 ID record_id,需要将其传递给每一行。但是这个record_id 列不能在前端显示(即需要隐藏)。我们如何通过 CI 做到这一点?
问题 #2 我应该使用哪种 JS 来允许用户单击该行并弹出一个带有用于编辑/删除的表单的弹出窗口?。
感谢您的帮助!
PS - 这里是生成表格数据的模型
function expenses_table()
{
$id = $this->tank_auth->get_user_id();
$this->db->select('record_id, date_format(date, \'%c/%d/%Y\'), plant_name, concat(\'$ \', format(value_1, 2)), value_2, value_3', FALSE);
$this->db->from('data');
$this->db->join('plants', 'plants.plant_id = data.plant_id_fk');
$this->db->where('category_1', 'expenses');
$this->db->where('data.id_fk', $id);
$this->db->order_by("date", "desc");
$query = $this->db->get();
return $query;
}
【问题讨论】:
标签: php jquery codeigniter datatables