在codeigniter中实现datatable插件

时间:2015-05-18 05:42:26

标签: json codeigniter datatable

我在codeigniter中使用jquery数据表插件和smarty模板。暂时我在控制器中编写代码(查询)。我在使用json_encode函数将json数据传递给ajax之前获取了所需的数据。数据表视图未加载。控制台中未显示错误。 Json数据未传递给视图。 任何帮助将不胜感激..

function jobseekers_list(){

    $this->CI = & get_instance();
    $this->DB = &$this->CI->db;

    $aColumns = array('id', 'fname', 'email');

    // DB table to use
    $sTable = 'users';  

    $this->DB->select('SQL_CALC_FOUND_ROWS '.str_replace(' , ', ' ', implode(', ', $aColumns)), false)->where('user_type', 1);
    $rResult = $this->DB->get($sTable);

    $this->DB->select('FOUND_ROWS() AS found_rows');
    $iFilteredTotal = $this->DB->get()->row()->found_rows;

    $iTotal = $this->DB->count_all($sTable);

    // Output
    $output = array(
        'sEcho' => intval($sEcho),
        'iTotalRecords' => $iTotal,
        'iTotalDisplayRecords' => $iFilteredTotal,
        'aaData' => array()
    );

    foreach($rResult->result_array() as $aRow)
    {
        $output['aaData'][] = $aRow;
    }

    echo json_encode($output);

}

这是我的视图文件... jquery 1.8.2包含在头文件

{include file="header.tpl"}

<link href='//cdn.datatables.net/1.10.7/css/jquery.dataTables.css' rel='stylesheet' type='text/css' media='screen' />
<!--<script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>-->
<script type="text/javascript" src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>

<table id="jsgrid" class="display" cellspacing="0" width="100%">
<thead>
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Email</th>

    </tr>
</thead>

<tfoot>
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Email</th>
    </tr>
</tfoot>
</table>

{literal}<script type="text/javascript">
$(document).ready(function(){
    $('#jsgrid').dataTable({
        "Processing": true,
        "ServerSide": true,
        "Ajax": "admin_users/jobseekers_list"

    });
}); 
</script>{/literal}

{include file="footer.tpl"}

0 个答案:

没有答案