单击行进行编辑/删除?
我正在使用 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;
}
I am using CI to generate a table
$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);
which runs through jQuery DataTables on client side using
$(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
} );
} );
Question #1
Each record on the database has a unique autoincrement ID record_id
that would need to be passed to each row. But this record_id
column cannot show in the front end (ie needs to be hidden). How do we do this via CI?
Question #2
What kind of JS should I use to allow the user to click on the row and get a popup with a form for edit/delete?.
Thanks for helping!
PS - here is the model to generate table data
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1.添加新列
编辑
2.根据每条记录的record_id构建编辑链接并隐藏record_id
3.使用 jQuery 与行交互:
有许多可用于 jQuery 的灯箱插件,它们可以接受 HTML。您需要做的就是创建一个 ajax 控制器来处理请求,使用模型来编辑/删除并以 JSON 形式返回结果。
jquery lightbox html (Google)
1. Add a new column
Edit
2. Build the edit link based on the record_id for each record and hide record_id
3. Use jQuery to interact with the rows:
There are many lightbox plugins available for jQuery, that can accept HTML. All you'll need to do is create an ajax controller to that handles the request, uses the model to edit/delete and return the result in JSON.
jquery lightbox html (Google)