[英]Datatable not working
大家好,我試圖使用數據表來反映我的數據庫,但是我沒有在數據表中得到結果。 需要幫助!!!
我的控制器:
public function __construct() {
parent::__construct();
$this->load->library('Datatables');
$this->load->library('table');
$this->load->database();
}
function index()
{
//set table id in table open tag
$tmpl = array ( 'table_open' => '<table id="big_table" border="1" cellpadding="2" cellspacing="1" class="mytable">' );
$this->table->set_template($tmpl);
$this->table->set_heading('Student ID','Name','Student Code','Class');
$this->load->view('subscriber_view');
}
//function to handle callbacks
function datatable()
{
$this->datatables->SELECT ('*', 'class')
->unset_column('student_id')
-> FROM ('students as s1')
->join ('student_class as s2','s1.class_id = s2.class_id');
echo $this->datatables->generate();
}
}
我的觀點:-
<html>
<head>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<title>Student Management</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/style.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/ui-lightness/jquery-ui.css" type="text/css" media="screen"/>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/jquery.dataTables.min.js"></script>
</head>
<body>
<div class="wrapper">
<script type="text/javascript">
$(document).ready(function() {
var oTable = $('#big_table').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": '<?php echo site_url('datatable'); ?>',
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"iDisplayStart ":20,
"oLanguage": {
"sProcessing": "<img src='<?php echo base_url(); ?>assets/images/ajax-loader_dark.gif'>"
},
"fnInitComplete": function() {
oTable.fnAdjustColumnSizing();
},
'fnServerData': function(sSource, aoData, fnCallback)
{
$.ajax
({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
});
}
} );
} );
</script>
<h1>Student Management</h1>
<?php echo $this->table->generate(); ?>
</div>
</body>
</html>
我的輸出:
{"sEcho":0,"iTotalRecords":2,"iTotalDisplayRecords":2,"aaData":[["1","Ahmad","Niza","451","AA1","A1"],["2","Ahmadi","Reza","452","AA2","A2"]],"sColumns":"*"}
此代碼有什么問題?
在此先感謝您的幫助。
嘗試添加以下行:
"sDom": "frti"
因此您的代碼如下所示:
var oTable = $('#big_table').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sDom": "frti" //added this line
"sAjaxSource": '<?php echo site_url('datatable'); ?>',
"bJQueryUI": true,
//rest of your code
根據數據表文檔 :
sDom:
這個初始化變量允許您確切地指定希望DataTables在DOM中的哪個位置注入它添加到頁面的各種控件(例如,您可能希望分頁控件位於表頂部)。 也可以添加DIV元素(帶有或不帶有自定義類)來輔助樣式設置。 使用以下語法:
允許以下選項:
'l' - Length changing 'f' - Filtering input 't' - The table! 'i' - Information 'p' - Pagination 'r' - pRocessing The following constants are allowed: 'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix') 'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix') The following syntax is expected: '<' and '>' - div elements '<"class" and '>' - div with a class '<"#id" and '>' - div with an ID Examples: '<"wrapper"flipt>' 'ip>'
最重要的一個是t
因為那是桌子。
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.