简体   繁体   中英

“Undefined table data” in codeigniter using datatables jquery

I have been trying to use datatables jquery plugin with codeigniter and still have no luck. I'm new with this api. (No ignitedTables please, just dataTables jquery plugin).

The view returns:

Undefined table data

Please see MVC below:

VIEW (where the script is incorporated)

<script type="text/javascript">
    $(document).ready(function() {
var oTable = $('#big_table').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "<?php echo site_url('home/calendarListAll/') ?>",
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "iDisplayStart ":20,
            "fnInitComplete": function() {
            //oTable.fnAdjustColumnSizing();
     },
            'fnServerData': function(sSource, aoData, fnCallback)
        {
          $.ajax
          ({
            'dataType': 'json',
            'type'    : 'POST',
            'url'     : sSource,
            'data'    : aoData,
            'success' : fnCallback
          });
        }
        } );
    } );
    </script>

    <html>
    <?php echo $this->table->generate(); ?> //this returns "Undefined table data"
    </html>    

CONTROLLER

function __construct()
{
 parent::__construct();
  $this->load->library('Datatables');
  $this->load->library('table');
  $this->load->database();
  $this->load->helper('url');
  $this->load->helper('form');
  $this->load->helper('html');
}

public function calendarListAll()
{
    $this->load->model('counselor');
    $result = $this->counselor->getCalendar();
    echo $this->datatables->generate($result);
}  

MODEL

function getCalendar() // get referred_appointments
{

    $counselor_id = $this->session->userdata('counselor_id');

    $query = $this->db->select ('s.first_name as student_fname, s.last_name as student_lname, s.middle_name as student_mname, e.first_name, e.last_name, e.middle_name, re.*, r.student_id, i.*, e.*')
    ->from ('referral as r, student_course_record as scr, curriculum as c, referred_appointment as re, degree as d, course as cc, counselor as ccc,  issue as i, student as s, employee as e')
    ->where ('r.student_id = scr.student_id')
    ->where ('scr.curr_id = c.curr_id')
    ->where ('c.degree_id = d.degree_id')
    ->where ('d.course_id = cc.course_id')
    ->where ('cc.counselor_id = ccc.counselor_id')
    ->where ('r.issue_id = i.issue_id')
    ->where ('r.student_id = s.student_id')
    ->where ('re.referral_id = r.referral_id')
    ->where ('r.employee_id = e.employee_id')
    ->where ('ccc.counselor_id', $counselor_id)
    ->where ('re.status != "C"');
    $ret = $query->get()->result();
    return $ret;

}

Use may it help you CI Help

$tmpl = array ('table_open' => '<table id="big_table">');
$this->table->set_template($tmpl);

忘记在generate $ this-> table-> generate($ records);中传递数据;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM