Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Help: load data in json format using ci
30/09/2012
13:50
Avatar
pohondigital
New Member
Members
Forum Posts: 1
Member Since:
30/09/2012
sp_UserOfflineSmall Offline

first, sory if my english is not good..

i develop a web using code igniter, and i have trouble when i want to load data to my grid

this is my code: the controller

<?php if(!defined('BASEPATH')) exit ('No direct script access allowed');

class Buku extends CI_Controller{
    function __construct(){
        parent::__construct();
        $this->load->model('m_buku');
    }
    
    function index(){
    }
    
    function Tampilkan_buku(){
        $data = $this->m_buku->tampilkan_buku();
        $this->load->view('daftar_buku',json_encode($data));
    }

}

/* End of file buku.php */
/* Location: ./application/controllers/buku.php */

the model

<?php if(!defined('BASEPATH')) exit ('No direct script access allowed');

class M_Buku extends CI_Model{
    function __construct(){
        parent::__construct();
    }
    
    function Total_record(){
        return $this->db->count_all('tbl_buku');
    }
    
    function Tampilkan_buku(){
        return $this->db->get('tbl_buku')->result_array();
    }
    
}

/* End of file model_buku.php */
/* Location: ./application/models/model_buku.php */

the views

<body>
<table id="tabel_buku"></table>
<div id="pager2″></div>

</body>
</html>

<script type="text/javascript">
    $(document).ready(function(){
        jQuery("#tabel_buku").jqGrid({
            url: '<?=base_url();?>buku/tampilkan_buku',
            datatype: "json",
            colNames:['Kode Buku','Judul Buku', 'Pengarang', 'Penerbit','Tahun','Jumlah','Keterangan'],
            colModel:[ {name:'kode_buku', index:'kode_buku',  width:100},
                       {name:'judul_buku',index:'judul_buku', width:300},
                       {name:'pengarang', index:'pengarang',  width:100},
                       {name:'penerbit',  index:'penerbit',   width:100, align:"right"},
                       {name:'tahun',     index:'tahun',      width:80, align:"right"},
                       {name:'jumlah',    index:'jumlah',     width:50, align:"right"},
                       {name:'keterangan',index:'keterangan', width:150, sortable:false}
            ],
            rowNum:20,
            rowList:[20,40,60],
            pager: '#pager2',
            sortname: 'kode_buku',
            viewrecords: true,
            sortorder: "desc",
            caption:"Daftar Buku"
        });
        
        jQuery("#tabel_buku").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});
    });
</script>

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
38 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information