Php 单击要编辑/删除的行?
我正在使用CI生成一个表Php 单击要编辑/删除的行?,php,jquery,codeigniter,datatables,Php,Jquery,Codeigniter,Datatables,我正在使用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 a
$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);
问题1
数据库中的每条记录都有一个唯一的自动增量IDrecord\u ID
,需要传递给每一行。但此记录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;
}
1。添加新列
Edit
$this->table->set_heading('Date', 'Plant', 'Expense', 'Category', 'Notes', 'Edit');
2。根据每条记录的记录id构建编辑链接,并隐藏记录id
$data = array();
while ($row = $query->result_array())
{
$anchor = '<a href="#" class="edit_record" record_id="' . $row['record_id'] . '">Edit</a>';
// Hide the record_id in the table output
unset($row['record_id']);
// Let's add the link so we can edit this entry
$row[] = $anchor;
// Lets push the new row so it can be output
$data[] = $row;
}
$table['tab'] = $this->table->generate($data);
有许多lightbox插件可用于jQuery,它们可以接受HTML。您只需创建一个ajax控制器来处理请求,使用模型编辑/删除并以JSON格式返回结果
@gary green-感谢您的回复--请查看我上面的更新,我添加了用于生成表数据的模型-我没有使用循环或
,而-知道如何在我的情况下取消设置记录id
?@gary green-另一个问题是取消设置将删除列,它不允许我使用record\u id
使每一行唯一化您实际需要的是什么?现在您谈论的是使每一行唯一?…是的-如上所述Question#1--数据库中的每一条记录都有一个唯一的自动增量ID record_ID,需要传递给每一行。但此记录id列无法显示在前端(即需要隐藏)。我们如何通过CI做到这一点?
——我需要每一行都是唯一的,这样当用户单击它时,该唯一ID(也称为记录ID)将允许编辑/删除该特定记录感谢更新!仍然不工作--请参阅我的OP,我在其中指出了代码的去向--我收到了一长页的错误,其中有未定义的索引:record\u id
--我没有在其他地方做任何更改(模型等)
$data = array();
while ($row = $query->result_array())
{
$anchor = '<a href="#" class="edit_record" record_id="' . $row['record_id'] . '">Edit</a>';
// Hide the record_id in the table output
unset($row['record_id']);
// Let's add the link so we can edit this entry
$row[] = $anchor;
// Lets push the new row so it can be output
$data[] = $row;
}
$table['tab'] = $this->table->generate($data);
$('a.edit_record').click(function() {
var record_id = this.attr('record_id');
// Lets generate the magical lightbox here...
});