单击行进行编辑/删除?

发布于 2024-10-26 22:46:16 字数 2019 浏览 0 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零崎曲识 2024-11-02 22:46:16

1.添加新列编辑

$this->table->set_heading('Date', 'Plant', 'Expense', 'Category', 'Notes', 'Edit');

2.根据每条记录的record_id构建编辑链接并隐藏record_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);

3.使用 jQuery 与行交互:

 $('a.edit_record').click(function() {
 var record_id = this.attr('record_id');

 // Lets generate the magical lightbox here...   

 });

有许多可用于 jQuery 的灯箱插件,它们可以接受 HTML。您需要做的就是创建一个 ajax 控制器来处理请求,使用模型来编辑/删除并以 JSON 形式返回结果。

jquery lightbox html (Google)

1. Add a new column Edit

$this->table->set_heading('Date', 'Plant', 'Expense', 'Category', 'Notes', 'Edit');

2. Build the edit link based on the record_id for each record and hide record_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);

3. Use jQuery to interact with the rows:

 $('a.edit_record').click(function() {
 var record_id = this.attr('record_id');

 // Lets generate the magical lightbox here...   

 });

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文