• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tombol Paging tidak berfungsi

#1
Sad 
[HELP]

selamat siang temen2 pengguna CI
saya mau bertanya
saya membuat tabel CRUD dengan JQGRID di framework Codeigniter
semua fungsi berjalan dengan normal dan tidak ada kendala di CRUD, Search
namun ketika klik tombol next page (pagination) tidak berfungsi,
jadi kalau ingin beralih page harus mengetik manual page yang dituju

berikut saya lampirkan Screenshootnya

ini code dari controllernya
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
jqgrid extends CI_Controller {

    function 
__construct()
    {
        
parent::__construct();
        
//$this->load->helper(array('url'));
        
$this->load->model('dosen_jqgrid_model');
        
//$this->load->database();
    
}

    function 
index()
    {
        
$this->load->view('jqgrid/home');
    }
    
    
    
// awal kode jadi    
    
function tampil_data(){
        
$data $this->dosen_jqgrid_model->getAllGrid(); //add parameter to model
        
$col = array(
            
'id_karyawan'=>'0','Row'=>'0','nama'=>'0',
            
'no_ktp'=>'0','alamat'=>'0',
            
'telp'=>'0'
        
);
        
$idnya "id_karyawan";
        
$records $data['records'];
        
$jmlRow $data['record_count'];
        
$total  $data['record_pages'];
        
$page = ($this->input->post('page')) ? $this->input->post('page') : 1;
        
        if(
$jmlRow <> 0){
            
header("Expires: Mon, 26 Jul 2020 05:00:00 GMT" );
            
header("Last-Modified: " gmdate"D, d M Y H:i:s" ) . "GMT" );
            
header("Cache-Control: no-cache, must-revalidate" );
            
header("Pragma: no-cache" );
            
header("Content-type: text/x-json");
            
$json "";
            
$json .= "{\n";
            
$json .= '"page": "'.$page.'",';
            
$json .= '"total": "'$total '",';
 
     $json .= '"records": "' $jmlRow'",';
            
$json .= '"rows": [';
            
$rc false;
            
$loop 1;
                foreach(
$records->result_array() as $row){
                    
$flexid $row[$idnya];
                    if (
$rc$json .= ",";
                    
$json .= "\n{";
                    
$json .= '"id":"'.$flexid.'",';
                    
$json .= '"cell":[';
                    
$i=0;
                    
                    foreach(
$col as $key => $value){
                        if(
$value==1){
                            
$cValue number_format($row[$key],2);
                        }elseif (
$value==3){ 
                            
//jumlah anka di belakang koma 
                            
$ArrVal explode(".",$row[$key]);
                                if(isset(
$ArrVal[1])) {
                                    
$lenght strlen($ArrVal[1]);
                                    
$cValue number_format($row[$key],$lenght);
                                }else{
                                    
$cValue number_format($row[$key],0);
                                }
                        }else{
                            
$cValue addslashes($row[$key]);
                        }
                        
$jisi $cValue;
                        
$json .= '"'.$jisi'"';
                    if(
$key!='telp'){
                        
$json .= ",";
                    }
                    
$i++;
                }
                
$json .= "]";
                
$json .= "}";
                
$rc true;
                
$loop++;
            }
            
$json .= "]\n";
            
$json .= "}";
            echo 
$json;
        }
        else
        {
                
$json "";
     
     $json .= "{\n";
     
     $json .= "}";            
                echo 
$json;
        }
    }
//akhir kode jadi

    
function hapusdata(){
        
$id_karyawan $this->input->post('id_karyawan');
        
        
$data = array(
            
'id_karyawan'=>$id_karyawan                         
        
);
        
$this->dosen_jqgrid_model->hapus($data);
        echo 
"berhasil";
    }
    
    function 
tambahdata(){
                
$nama $this->input->post('nama');
                
$no_ktp $this->input->post('no_ktp');
                
$alamat $this->input->post('alamat');
                
$telp $this->input->post('telp');
                
                
$data = array(
                        
//'id_karyawan'=>$id_karyawan,
                        
'nama'=>$nama,
                        
'no_ktp'=>$no_ktp,
                        
'alamat'=>$alamat,
                        
'telp'=>$telp,                        
                );
                
$this->dosen_jqgrid_model->tambah($data);
                echo 
"data berhasil disimpan";
    }
    
    function 
proses_ubah(){
                
$id_karyawan $this->input->post('id_karyawan');
                
$nama $this->input->post('nama');
                
$no_ktp $this->input->post('no_ktp');
                
$alamat $this->input->post('alamat');
                
$telp $this->input->post('telp');
                
                
$data = array(
                        
'id_karyawan'=>$id_karyawan,
                        
'nama'=>$nama,
                        
'no_ktp'=>$no_ktp,
                        
'alamat'=>$alamat,
                        
'telp'=>$telp,                        
                );
        
$this->dosen_jqgrid_model->ubah($data);
        echo 
$this->db->last_query();
        echo 
"berhasil";
    }
    
    function 
popup($param=null){
        
//    echo $this->load->view('index.php/jqgrid/v_jqgrid_insert/');
        //$html.= form_open('cinsertdata/tambahdata');
        
$row="";
        if(
$param!=null){
            
$hasil=$this->dosen_jqgrid_model->filterdata($param);
            
$row=$hasil;
        }
        
        echo 
'
            <style type="text/css">
            #tabel{
                border: 1px solid #D6DDE6;
                border-collapse: collapse;
            }
            .warna{
                color: white;
            }
            </style>
        '
;
        
        
        
        
$html'
        <table border="0px" >
        <tr>
      <td class="warna"></td>
      <td class="warna"></td>
      <td>
            '
;
                echo 
form_hidden('id_karyawan'$row==""?"":$row->id_karyawan);
                
//$data = array(
                    //'name'        => 'id_karyawan',
                    //'id'          => 'id_karyawan',
                    //'value'       => $row==""?"":$row->id_karyawan,
                
                //);
                //$html.=  form_hidden($data);
                
$html.=    '
            </td>
    </tr>
        
        <tr>
        <td class="warna">Nama</td>
        <td class="warna">:</td>
        <td>
                '
;
                
                        
$data = array(
                        
'name'        => 'nama',
                        
'id'          => 'nama',
                        
'value'       => $row==""?"":$row->nama,
                        
'maxlength'   => '100',
                        
'size'        => '50',
                        
'style'       => 'width: 470px',
                        );
 
       
                        $html
.=  form_input($data);
                        
$html.=        '
                </td>
    </tr>
        
    <tr>
        <td class="warna">No KTP</td>
        <td class="warna">:</td>
        <td>'
;
                
                
$data = array(
                        
'name'        => 'no_ktp',
                        
'id'          => 'no_ktp',
                        
'value'       => $row==""?"":$row->no_ktp,
                        
'maxlength'   => '100',
                        
'size'        => '50',
                        
'style'       => 'width: 470px',
 
       );
        
$html.= form_input($data);
        
$html.='</td>
    </tr>
    <tr>
        <td class="warna">Alamat</td>
        <td class="warna">:</td>
        <td>'
;
                
                
$data = array(
                        
'name'        => 'alamat',
                        
'id'          => 'alamat',
                        
'value'       => $row==""?"":$row->alamat,
                        
'maxlength'   => '1000',
                        
'size'        => '50',
                        
'style'       => 'width: 470px',
 
       );
        
$html.= form_input($data);
        
$html.='</td>
    </tr>
        <tr>
        <td class="warna">Telp</td>
        <td class="warna">:</td>
        <td>'
;
                
                
$data = array(
                        
'name'        => 'telp',
                        
'id'          => 'telp',
                        
'value'       => $row==""?"":$row->telp,
                        
'maxlength'   => '100',
                        
'size'        => '50',
                        
'style'       => 'width: 470px',
 
       );
            
$html.= form_input($data);
                
        
$html.='</td>
    </tr>
    
    </table>'
;
    echo 
form_close();

    echo 
$html;
        
    }
    
}
?>


ini code dari modelnya

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

class 
Dosen_jqgrid_model extends CI_Model{

    function 
__construct(){
        
parent::__construct();
    }
    
    function 
index(){
        
$q $this->db->query("select * from karyawan");
     
 return $q;
 
 }
    
    function 
ubah($data){
        
$id_karyawan $this->input->post('id_karyawan');
 
   $nama $this->input->post('nama');
 
   $no_ktp $this->input->post('no_ktp');
 
   $alamat $this->input->post('alamat');
 
   $telp $this->input->post('telp');
 
       
        $data 
= array(
 
     //'id_karyawan'=>$id_karyawan,
 
     'nama'=>$nama,
 
     'no_ktp'=>$no_ktp,
 
     'alamat'=>$alamat,
 
     'telp'=>$telp
    
);
 
   $this->db->where(array('id_karyawan'=>$id_karyawan));
 
   $this->db->update('karyawan',$data);
 
 }
 
 
 function filterdata($id_karyawan){
 
   return $this->db->get_where('karyawan',array('id_karyawan'=>$id_karyawan))->row();
 
 }
    
    function 
hapus($data){
        
$this->db->delete('karyawan',$data);
        echo 
$this->db->last_query();
    }
    
    function 
tambah($data){            
        
$this->db->insert('karyawan',$data);
 
 }

//awal kode jadi    
    
function getAllGrid(){        
        
$page $this->input->post('page');
        
$rp = ($this->input->post('rp')) ? $this->input->post('rp') : $this->input->post('rows');
        
$sortname = ($this->input->post('sortname')) ? $this->input->post('sortname') : $this->input->post('sidx');
        
$sortorder = ($this->input->post('sortorder')) ? $this->input->post('sortorder') : $this->input->post('sord');
        
$sorting " ORDER BY ".$sortname." ".$sortorder;
        
$start = ($page $rp) - $rp;
        
 
   $this->db->select('id_karyawan,nama,no_ktp,alamat,telp');
        
$this->db->select('ROW_NUMBER() OVER ('.$sorting.') AS Row');
        
$this->db->from('karyawan');
        
        
//$this->db->where("isnull(nama,'') <> ''");
        //$this->db->where("isnull(no_ktp,'') <> ''");
        //$this->db->where("isnull(alamat,'') <> ''");
        //$this->db->where("isnull(telp,'') <> ''");
        
        
if($this->input->post('_search')){
            switch(
$this->input->post('searchOper')){
                
//sama persis
                
case 'eq':
                    
$this->db->where($this->input->post('searchField'),
                                                     
$this->input->post('searchString'));
                    break;
                case 
'ne':
                    
$this->db->where($this->input->post('searchField').'!=',
                                                     
$this->input->post('searchString'));
                    break;
                
//salah satu yg ada
                
case 'cn':
                    
$this->db->where($this->input->post('searchField')." LIKE '%".
                                                     
$this->input->post('searchString')."%'",NULL,FALSE);
                    break;
            }
        }
        
$sql $this->db->_compile_select();
        
$this->db->_reset_select();
        
        
$this->db->select('*');
        
$this->db->from("($sql)A");
 
   $this->db->where('Row > '$start .' AND Row <= '$page $rp);
 
   
    $query 
$this->db->get();
 
   // echo $this->db->last_query();
 
   $return['records'] = $query;
        
$return['record_count'] = $query->num_rows();
 
   $return['record_pages'] = ($query->num_rows()> 0) ? ceil($query->num_rows()/ $rp) : 0;//setting jumlah halaman
 
   return $return;
 
 }
//akhir kode jadi

}
?>

dan ini code dari view


PHP Code:
<html>
 
   <head>
 
       <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/dark-hive/jquery-ui.css" type="text/css" rel="stylesheet"/>
 
       <link href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" rel="stylesheet"/>
 
       <link type="text/css" href="<?php echo base_url()?>asset/jqgrid/css/ui.jqgrid.css" rel="stylesheet" />
 
       <link type="text/css" href="<?php echo base_url()?>asset/jqgrid/css/jquery.searchFilter.css" rel="stylesheet" />
 
       <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js" type="text/javascript"></script>
        <script src="<?php echo base_url(); ?>asset/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script> 
        <script src="<?php echo base_url(); ?>asset/jqgrid/js/jquery.jqGrid.js" type="text/javascript"></script>
        <script src="<?php echo base_url(); ?>asset/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
 
        <title>Data Jqgrid</title>
    </head>

    <body> 
        <script type="text/javascript">
            jQuery().ready(function(){
                //alert ("halo");
                $("#daftar_karyawan").jqGrid({
                    url:'/index.php/jqgrid/tampil_data',
                    datatype: 'json',
                    mtype : 'post',
                    //colNames:['ID','No','Nama','No KTP','Alamat','Telp',''], 
                    colNames:['ID','No','Nama','No KTP','Alamat','Telp'], 
                    colModel:[
                        {name:'id_karyawan',index:'id_karyawan', width:10, align:"center",hidden:true},
                        {name:'Row',index:'Row', width:4, align:"center"},
                        {name:'nama',index:'nama', width:15, align:"center"},
                        {name:'no_ktp',index:'no_ktp', width:10, align:"center"},
                        {name:'alamat',index:'alamat', width:40, align:"center"},
                        {name:'telp',index:'telp', width:10, align:"center"},
                        //{name: '', index: 'action', width:75, sortable:false, formatter:'actions',
                        //    formatoptions:{
                        //        editbutton: false, delbutton:true, mtype: "POST",
                        //        delOptions:{
                        //            caption: 'Hapus',
                        //            msg: 'Anda ingin menghapus record ini?',
                        //            bSubmit: 'Hapus',
                        //            mtype: 'POST',
                        //            url: '/index.php/jqgrid/hapusdata',
                        //            bCancel: 'Batal'
                        //        }
                        //    }
                        //}
                        
                    ],
                    rowNum:10,
                    width: 1240,
                    height: 230,
                    //autoheight: true,
                    //autowidth: true,
                    pgbuttons: true,
                    loadOnce: true,
                    rowList:[10,20,30,40,50,60,70,80,90],
                    pager: '#pager1',
                    sortname: 'id_karyawan',
                    sortorder: "asc",
                    viewrecords: true, 
                    caption:"Daftar Karyawan",
                    
                }).jqGrid('navGrid','#pager1',{edit:true,add:true,del:true,search:true,
                    editfunc:function(){ jvEdit();},
                    addfunc:function(){ jvAdd();},
                    delfunc:function(){ jvDel();}
                    })
            });
            
            function jvEdit(){
                $("#dialog").dialog({
                        autoOpen: false,
                        title: 'Add',
                        modal: true,
                        width: '585',
                        height: '500',
                        resizable: false,
                        closeOnEscape: false,
                        buttons: {
                          'Simpan': function() {
                            jvUpdate();
                          },
                          Tutup: function() {
                              $(this).dialog('close');
                          }
                        },
                        close: function() {
                          if($("#popup").dialog('isOpen')){
                            $("#popup").dialog('close');
                          }
                          $("#popup").dialog('destroy');
                          $(this).dialog('destroy');
                          $(this).empty();
                        }
                      });
                var rec={};
                
                var rowPopID = $('#daftar_karyawan').jqGrid('getGridParam','selrow');
                rec['id_karyawan']=rowPopID;
                //alert(rowPopID);
                
                $("#dialog").dialog("option","title",'Ubah Data').dialog('open');
                $("#dialog").load('<?php echo base_url(); ?>index.php/jqgrid/popup/'+rowPopID,function(){
                    $('.ui-button ui-widget ui-state_default ui-corner-all ui-button-text-only button:first').html('Confirm');
                });
            }
            
            function jvUpdate() {
                var rec={};
                rec['id_karyawan']=$('[name = "id_karyawan"]').val();
                rec['nama']=$('#nama').val();
                rec['no_ktp']=$('#no_ktp').val();
                rec['alamat']=$('#alamat').val();
                rec['telp']=$('#telp').val();
                
                $.post('<?=$this->config->item('base_url')?>index.php/jqgrid/proses_ubah',
                rec,function(data){
                alert(data);
                $("#dialog").dialog("close");
                
                });
            }
            
            function jvDel(){
                //alert($('#id_karyawan').val());
                var rec={};
                
                var rowPopID = $('#daftar_karyawan').jqGrid('getGridParam','selrow');
                rec['id_karyawan']=rowPopID;
                //alert(rowPopID);
                
                if (confirm("Yakin ingin di hapus?")!= true) {
                    return;
                }
                $.post('<?=$this->config->item('base_url')?>index.php/jqgrid/hapusdata',
                rec,function(data){
                });
            }
            
            function jvSave() {
                //code             
                // alert($('#no_ktp').val());
                var rec={};
                rec['nama']=$('#nama').val();
                rec['no_ktp']=$('#no_ktp').val();
                rec['alamat']=$('#alamat').val();
                rec['telp']=$('#telp').val();
                
                $.post('<?=$this->config->item('base_url')?>index.php/jqgrid/tambahdata',
                rec,function(data){
                alert(data);
                $("#dialog").dialog("close");
                
                });
            }
             function jvAdd(){
                //alert('hayyooo');
                $("#dialog").dialog({
                        autoOpen: false,
                        title: 'Add',
                        modal: true,
                        width: '585',
                        height: '500',
                        resizable: false,
                        closeOnEscape: false,
                        buttons: {
                          'Simpan': function() {
                            jvSave();
                          },
                          Tutup: function() {
                              $(this).dialog('close');
                          }
                        },
                        close: function() {
                          if($("#popup").dialog('isOpen')){
                            $("#popup").dialog('close');
                          }
                          $("#popup").dialog('destroy');
                          $(this).dialog('destroy');
                          $(this).empty();
                        }
                      });
                $("#dialog").dialog("option","title",'Tambah Data').dialog('open');
                $("#dialog").load('<?php echo base_url(); ?>index.php/jqgrid/popup',function(){
                    $('.ui-button ui-widget ui-state_default ui-corner-all ui-button-text-only button:first').html('Confirm');
                });
            }
        </script>
   
    <table id="daftar_karyawan"></table>
    <div id="pager1"></div>
    <div id="dialog"></div>
    <div id="dialog2"></div>
    <div id="popup"></div>
    
    </body>
</html> 



mohon bantuannya,,,,
sebelumnya terimakasih banyak,,,, Confused


Attached Files Thumbnail(s)
   
Reply

#2
Halo, mungkin kamu bisa lihat guide resmi untuk pagination dari situs codeigniter:

https://www.codeigniter.com/userguide3/l...ation.html

atau tutorial dari sitepoint ini:

https://www.sitepoint.com/pagination-with-codeigniter/
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.