baru berhasil tadi sore...
karena kita pake datatype json jadi kita harus tambahin helper json di codeigniter kita..
Download disini
kopiin isi file donlotannya di "system/helper"
bikin tablenya contoh:
CREATE TABLE `konsep` ( `id` int(11) NOT NULL AUTO_INCREMENT, `nm_konsep` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
INSERT INTO `konsep` (`id`,`nm_konsep`) VALUES (1,'Seni/Budaya'), (2,'Sejarah'), (3,'Komunikasi'), (4,'Profesi'), (5,'Kuliner'), (6,'Proses'), (7,'Go Green'), (8,'Back To Nature');
Bikin Controller
file controllers/konsep.phpclass konsep() extends Controller{ public function konsep(){ parent::Controller; } public function index(){ load-> vars($data); $this->load->view('admin'); } public function getlistkonsep(){ $sidx = $this->input->post('sidx'); $sord = $this->input->post('sord'); $page = $this->input->post('page'); $limit = $this->input->post('rows'); $this->load->helper('json'); $konsep=$this->mkonsep->gridcountkonsep(); $count=count($konsep); if( $count > 0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } if ($page > $total_pages) $page=$total_pages; $start = $limit*$page - $limit; if ($start<0 row="$this-" start="0;">mkonsep->gridkonsep($sidx,$sord,$start,$limit); $response['page'] = $page; $response['total'] = $total_pages; $response['records'] = $count; $response['start'] = $limit*$page - $limit; $i=0; $rowid=0; foreach ($row as $r) { $response['rows'][$i]['no']=$r["id"]; $response['rows'][$i]['cell']=array($r['id'],$r['nm_konsep']); $i++; } echo json_encode($response); } } 0>
Bikin Modelnya
file models/mkonsep.phpclass mkonsep() extends Model{ public function mkonsep(){ parent::Model; } function gridkonsep($idx,$ord,$start,$limit) { $data = array(); $this-> db-> select('*'); $this-> db-> from('konsep'); $this->db->order_by($idx,$ord); $this->db->limit($limit,$start); $Q = $this-> db-> get(); if ($Q-> num_rows() > 0){ foreach ($Q-> result_array() as $row){ $data[] = $row; } } $Q-> free_result(); return $data; } function gridcountkonsep(){ $data = array(); $this-> db-> select('*'); $this-> db-> from('konsep'); $Q = $this-> db-> get(); if ($Q-> num_rows() > 0){ foreach ($Q-> result_array() as $row){ $data[] = $row; } } $Q-> free_result(); return $data; } }
bikin viewnya
filenya views/admin.php//di viewnya tambahin css dan javascript yang dibutuhinuntuk pathnya.. di sesuaikan aja ya ma agan2 sekalian hihihi pasti bisa lah :)//cssnya yg di load
<link rel="stylesheet" type="text/css" href="<?=base_url();?>css/theme/south-street/jquery-ui-1.7.2.custom.css"/>
<link rel="stylesheet" type="text/css" media="screen" href="<?=base_url();?>css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="<?=base_url();?>css/ui.multiselect.css" />
//javascript yg di load
<script type="text/javascript" src="<?=base_url();?>scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="<?=base_url();?>scripts/jquery-ui-1.7.2.custom.min.js"></script>
<script src="<?=base_url();?>scripts/jquery.layout.js" type="text/javascript"></script>
<script src="<?=base_url();?>scripts/i18n/grid.locale-en.js" type="text/javascript"></script><script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script src="<?=base_url();?>scripts/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="<?=base_url();?>scripts/jquery.tablednd.js" type="text/javascript"></script>
<script src="<?=base_url();?>scripts/jquery.contextmenu.js" type="text/javascript"></script>
<script src="<?=base_url();?>scripts/ui.multiselect.js" type="text/javascript"></script>
//dan ini untuk menampilkan jqgridnya....
<table id="list2"></table>
<div id="pager2">
</div>
//javascript ini harus di taro setelah table yang diatas itu...
<script type="text/javascript">
jQuery("#list2").jqGrid({
url:'admin/getlistkonsep',
datatype: "json",
mtype : "post",
autowidth:true,
autoheight:true,
colNames:['id','Konsep'],
colModel:[
{name:'id',index:'id', width:55},
{name:'nm_konsep',index:'nm_konsep', width:90,sortable:false}
],
rowNum:7,
rowList:[7,14,21],
pager: '#pager2',
sortname: 'id',
viewrecords: true,
sortorder: "asc",
caption:"List Konsep"
});
jQuery("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false,search:false});
</script>
sayang ya jqgrid jadi berbayar sekarang :(
good luck...
3 komentar:
gan scriptnya yg lengkap dunk, ane masih kesulitan nih... maklum nyubi di CI :)
thanks b4
yang kurang jelasnya sebelah mana gan... hihihi...
makasi dah mampir..
di file view ada dituliskan ;
url:'admin/getlistkonsep',
apakah isi dari informasi url ini?
karena kalau diakses dr contoh jqgrid (www.trirand.com/blog/) "url :" diisi dengan file php. saya sangat ingin belajar CI dan jqgrid. mohon pencerahannya. thx..
Posting Komentar