我一直在尝试使用带有codeigniter的datatables jquery插件,但仍然没有运气。 我是这个api的新手。 (请不要点燃表,只需要dataTables jquery插件)。
视图返回:
未定义的表格数据
请参阅下面的MVC:
VIEW(包含脚本的地方)
<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;
}
答案 0 :(得分:0)
使用可能会对您有所帮助CI Help
$tmpl = array ('table_open' => '<table id="big_table">');
$this->table->set_template($tmpl);
答案 1 :(得分:0)
忘记在生成中传递数据 $这 - &GT;表 - &GT;生成($记录);