最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - datatable showhide columns with checkbox - Stack Overflow

programmeradmin3浏览0评论

I have a code in codeigniter, and i am using a data-table, now i want to make a show/hide columns with a checkbox above to let the columns hide or maybe shown. I will populate my data from my database in my controller with these code :

public function dataTable_report($date) {
        $user = array('user_id' => $this->session->userdata['logged_in']['user_id']);
        $myreport = $this->Adminreport_model->getreportDataDaily($user,$date);

        $data = array();
        foreach ($myreport as $patient) {
            $row = array();  
            $row[] = $patient->check_up_id;
            $row[] = $patient->patient_fname;
            $row[] = $patient->patient_lname;
            $row[] = $patient->patient_mname;
            $row[] = $patient->check_up_date;
            $row[] = $patient->clinic_name;
            $row[] = $patient->bill_amt;

            $data[] = $row;
        }
        $output = array(   
            "data" => $data,
        );
        echo json_encode($output);
    }

now here is my data-table that doesn't hide when i check my checkbox above please help me: /

I have a code in codeigniter, and i am using a data-table, now i want to make a show/hide columns with a checkbox above to let the columns hide or maybe shown. I will populate my data from my database in my controller with these code :

public function dataTable_report($date) {
        $user = array('user_id' => $this->session->userdata['logged_in']['user_id']);
        $myreport = $this->Adminreport_model->getreportDataDaily($user,$date);

        $data = array();
        foreach ($myreport as $patient) {
            $row = array();  
            $row[] = $patient->check_up_id;
            $row[] = $patient->patient_fname;
            $row[] = $patient->patient_lname;
            $row[] = $patient->patient_mname;
            $row[] = $patient->check_up_date;
            $row[] = $patient->clinic_name;
            $row[] = $patient->bill_amt;

            $data[] = $row;
        }
        $output = array(   
            "data" => $data,
        );
        echo json_encode($output);
    }

now here is my data-table that doesn't hide when i check my checkbox above please help me: https://jsfiddle/2j6w9hqt/27/

Share Improve this question asked Feb 27, 2017 at 4:08 Jc JohnJc John 1,8592 gold badges41 silver badges78 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

I would not remend manipulating columns visibility by just hiding th element.

Instead look into using Buttons extension and colvis button.

$('#example').DataTable( {
    dom: 'Bfrtip',
    buttons: [
        {
            extend: 'colvis',
            columns: ':not(:first-child)'
        }
    ]
} );

See this example for code and demonstration.

I have also modified default appearance of the column visibility button by adding checkboxes, see this answer for more details.

发布评论

评论列表(0)

  1. 暂无评论