【问题标题】:Codeigniter: How do I add a column with checkboxes for multiple select and delete using jQueryCodeigniter:如何使用 jQuery 添加带有多选和删除复选框的列
【发布时间】:2016-03-01 13:56:19
【问题描述】:

我遇到了一个问题,我需要复选框来删除多个候选人,而不是单独删除它们。我正在使用 codeigniter 和数据表(jQuery)

    <?php echo $this->table->generate(); ?>

这就是它在视图中的加载方式。下面我将放置我的控制器:

    public function index ()
    {
        // Fetch all users
        // $this->data['tasks'] = $this->task_m->get();
        //datatable
        $tmpl = array ( 'table_open'  => '<table id="big_table" border="1" cellpadding="2" cellspacing="1" class="table ">' );
        $this->table->set_template($tmpl); 
        $this->table->set_heading('Select','Client Name','Subject','Booking Date','Status','Actions');

        // Load view
        $this->data['subview'] = 'admin/task/index';
        $this->load->view('admin/_layout_main', $this->data);
    }

下面是我的模型:

    public function list_tasks(){
    $userID = $this->session->userdata('id');

   $this->datatables->select("ci_customer.firstname,ci_task.subject_desc, ( DATE_FORMAT ( ci_task.booking_date ,('%d/%m/%Y
    '))), IFNULL( ( select c.pinged_status from ci_task_revisions c where c.task_id = ci_task.task_id order by revision_id desc limit 1 ), (ci_task.status) ) as status, ci_task.task_id,(CASE WHEN Date(ci_task.due_date) < CURDATE() AND ci_task.status <>'COMPLETE' THEN 'overdue' WHEN ci_task.assigner_id=ci_task.assignee_id THEN 'self' WHEN ci_task.assigner_id =$userID THEN 'assignee'  WHEN ci_task.assignee_id =$userID THEN 'assigner'  ELSE 'default'  END ) as type, ci_task.read")
    ->join('ci_customer','ci_customer.customer_id = ci_task.customer_id');


    $where = 'ci_task.assigner_id ='.$userID.' OR ci_task.assignee_id ='.$userID.'';
    $this->datatables->where($where);

    $this->datatables->edit_column('ci_task.task_id', btn_edit('admin/task/edit/' . '$1').' '.btn_sms('admin/task/sendSMS/' . '$1').' '.($this->session->userdata('role')?btn_delete('admin/task/delete/' .  '$1'):'')  ,'ci_task.task_id')
    ->from($this->_table_name);
    return $this->datatables->generate();
}

任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: php jquery codeigniter datatables


    【解决方案1】:

    如果你只是想知道如何显示复选框,jQuery 数据表内置了这个功能。您需要添加:

    <input name="select_all" value="1" type="checkbox">
    

    您可以在 jsfiddle http://jsfiddle.net/gyrocode/abhbs4x8/ 上查看此示例

    【讨论】:

    • 我可以在set_heading函数中输入... table->generate(); ?> 但是我如何像这样在视图中添加它?
    【解决方案2】:

    在输入名称中使用方括号。

    <input name="candidates[]" value="1" type="checkbox">
    <input name="candidates[]" value="2" type="checkbox">
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      • 2020-08-05
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多