English 中文(简体)
Jquery 插件
原标题:how to create serverside datatable with codeigniter and datatables Jquery plugin

我使用有data tasks Jquery插件的编码程序。

I have about 3000 rows of record to be displayed in a table (i m using postgresql). But i don t want the entire records to be loaded in the first time (it will slow the page load down). Instead. I prefer to make it separated into several pages and load it according to user action when user hit the next button. I have struggle with some code I made, but it still display an entire records with "Showing 1 to NaN of NaN entries (filtered from NaN total entries)" at the bottom of the table. This is my code.

主计长:

<?php

class Testdata extends CI_Controller
{
    function __consrtuct()
    {
        parent::__consrtuct();
    }

    function index()
    {
        $this->load->view( vtestdata );
    }

    function getData()
    {

        $this->load->model( mtestdata );
        $result = $this->mtestdata->getDatax();
        echo json_encode($result);

    }
}

模式:

<?php

class Mtestdata extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }


    function getDatax()
    {

        //output
        $output = array(
                "aData" => array()
            );
        $this->db->select( nik, user_name );
        $query=$this->db->get( t_mtr_user );
        $output["aData"] = $query->result();
        return $output;
    }
}

视图 :

<head>
    <script type="text/javascript" src="<?php echo base_url();?>/assets/media/js/jquery.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>/assets/media/js/jquery.dataTables.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>/assets/jqueryUI/js/jquery-ui-1.8.20.custom.min.js"></script>

    <script type="text/javascript">
        $( document ).ready( function() {

            $( #testTable ).dataTable({


                "bJQueryUI": true, //UI
                "sAjaxSource": "<?=base_url();?>index.php/testdata/getData", //datasource
                "sAjaxDataProp": "aData", //menentukan array/json dibaca dari mana
                "bServerSide": true, //serverside , ini yg bermasalah, kalo di delete beres gak ada error, tapi gak SSP
                "bProcessing": true,
                "aoColumns":[ //tentukan kolom pd tabel dan value nya
                    {"mDataProp": "nik", "sTitle": "NIK"},
                    {"mDataProp": "user_name", "sTitle": "Username"}
                ] 


           });
        });



    </script>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/assets/jqueryUI/css/custom-theme/jquery-ui-1.8.20.custom.css">
</head>
<body>
<div>
<h1>test</h1>
<table id="testTable">
    <thead>
        <!--
        <tr>
        <th>nik</th>
        <th>User name</th>
        </tr>
        -->
    </thead>
    <tbody>
    <!--
        <td></td>
        <td></td>
        -->
    </tbody>
</table>
</div>
</body>

有任何建议吗 我真的很感激你的帮助

问题回答

取而代之的是这个“https://github.com/blake-nouribekian/codigniter-databables” rel=“nofollow” >code 。我用它制作了数据表,效果很好。如果你对它有问题,请告诉我。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签