pass multi dimension array to datatables in codeigniter

pass multi dimension array to datatables in codeigniter

dinyomagedinyomage Posts: 1Questions: 1Answers: 0
edited December 2018 in Free community support

Hi Everyone,

I have use datatables for my website (I use codeIgniter framwork) and it's work. but now i have problem when I use multi dimension array,

this my code

        function data_attend()
        {
            $w          = $this->input->post("write");
            $d          = $this->input->post("delete");
            $lab_slct           = $this->input->post("lab_slct");
            $month_slct = $this->input->post("month_slct");
            $year_slct  = $this->input->post("year_slct");
            $draw       = intval($this->input->get("draw"));
                    $start      = intval($this->input->get("start"));
                    $length             = intval($this->input->get("length"));
            $data = array();
            $attend_test    = $this->m_human_capital->attend_test();
            $month = $this->m_general->month($month_slct)->row_array();
            $day_total  = $month['day_total'];
            $holiday    = $this->m_general->holiday()->result();
            $month      = $this->m_general->list_month()->result();
            $year       = $this->m_general->list_year()->result();
            $rows       = $this->m_human_capital->attendance($lab_slct, $keyword)->result_array();
            $a          = array();
            foreach ($rows as $row) {
                $a[$row['sn']][] = $row;
            }
                $rows2          = $a;
            $attendance_2   = $this->m_human_capital->attendance_2(array('ab.lab'=>$lab_slct));
            $roaster        = $this->m_general->get_data('tb_roaster')->result_array();
            $attend_detail  = $this->m_general->get_data('tb_attend_detail')->result_array();
            $no=1;
            foreach ($attendance_2->result_array() as $attend_list) {
                foreach ($rows2 as $i){
                    if ($i = $attend_list['sn']) {
                        $a = $attend_list['name'];
                        $b = $attend_list['pst_desc'];
                        for($m=1; $m <= $day_total; $m++){
                            $c=$m;
                        }
                        $d = array();
                        $d[] = implode(',',$c);
                    }
                }
                $data[] = array (
                    $no++,
                    $a,
                    $b,
                    $d (i want to show array $d here)
                );
            }
            $output = array(
                        "draw"              => $draw,
                    "recordsTotal"      => $attendance_2->num_rows(),
                    "recordsFiltered"   => $attendance_2->num_rows(),
                    "data"              => $data
                );
            echo json_encode($output);
        }

this my javascript

 $(document).ready(function() {
        $("#attendance_list").DataTable({
            "ajax": {
                "url": base_url+"human_capital/data_attend",
                "type": "POST",
                "data": {
                    "write": $("#write").val(),
                    "delete": $("#delete").val(),
                    "lab_slct": $("#lab_slct").val(),
                    "month_slct": $("#month_slct").val(),
                    "year_slct": $("#year_slct").val()
                }
            }
        });
    });

my data just show column 1 until 3, but for column 4 just shown last array $d.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @dinyomage ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.