Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Pagging ga sesuai jika text di input codeigniter

Siang master,
Saya form search
image
kalau user input nama di text (Contoh herr)
image
muncul nama herry, yang jadi masalah kalau saya klik page ke 2, hasilnya
image
jadi kalau halaman ke 2 dst itu balik lagi ke kondisi kalau text nya kosong. Jadi kayanya pas klik halaman ke 2 formnya ke reset jadi kosong.
saya pake CI di sini.
view
<form role="form">
<input type="text" class="form-control" id="search" placeholder="Search..." x-webkit-speech>
<span class="input-group-btn">
<button class="btn btn-default" id="btn-search"><i class="fa fa-search"></i></button>
</span>
</form>
<table id="data-table" class="table table-striped table-bordered table-hover" >
<thead>
<tr>
<th>#</th>
<th>NIK</th>
<th>Nama Lengkap</th>
<th>Tanggal Cuti</th>
<th>Keterangan</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<!--Appended by Ajax-->
</tbody>
</table>
<div class="pull-right">
<ul class="pagination"></ul>
</div>
<script>
 
function get_data(url,q){
 
if(!url)
url = base_url+'cuti/data_cuti_karyawan/get_data';
 
$.ajax({
 
url:url,type:'post',dataType:'json',
data:{q:q},
success:function(result){
 
$("#data-table tbody").html(result.rows);
$("ul.pagination").html(result.paging);
$(".page-info").html(result.page_info);
}
 
});
}
function do_search(){
 
 
get_data('',$("#search").val());
 
}
$(function(){
 
get_data();//initialize
 
$(document).on('click',"ul.pagination>li>a",function(){
 
var href = $(this).attr('href');
get_data(href);
 
return false;
});
 
$("#search").keypress(function(e){
 
var key= e.keyCode ? e.keyCode : e.which ;
if(key==13){ //enter
 
do_search();
}
 
});
 
$("#btn-search").click(function(){
 
do_search();
 
return false;
});
 
});
 
</script>
Controller
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Data_cuti_karyawan extends CI_Controller{
 
public function get_data(){
$limit = $this->config->item('limit');
$offset= $this->uri->segment(4,0);
$q = isset($_POST['q']) ? $_POST['q'] : '';
$data = $this->data_cuti_karyawan_model->get_data($offset,$limit,$q);
$rows = $paging = '';
$total = $data['total'];
 
if($data['data']){
 
$i= $offset+1;
$j= 1;
foreach($data['data'] as $r){
 
$rows .='<tr>';
 
$rows .='<td width="3%">'.$i.'</td>';
$rows .='<td width="5%">'.$r->nik.'</td>';
$rows .='<td width="20%">'.$r->nama_lengkap.'</td>';
$rows .='<td width="10%" align="center">'.$r->tanggal_cuti.'</td>';
//$rows .='<td width="10%" align="center">'.$r->tahun.'</td>';
$rows .='<td width="17%">'.$r->keterangan.'</td>';
$rows .='<td width="20%" align="center">';
 
$rows .='<a title="Edit" class="a-success" href="'.base_url().'cuti/data_cuti_karyawan/detail/'.$r->id_cuti_karyawan.'">
<i class="fa fa-lightbulb-o"></i> Detail
</a> ';
$rows .='<a title="Edit" class="a-warning" href="'.base_url().'cuti/data_cuti_karyawan/edit/'.$r->id_cuti_karyawan.'">
<i class="fa fa-pencil"></i> Edit
</a> ';
$rows .='<a title="Delete" class="a-danger" href="'.base_url().'cuti/data_cuti_karyawan/delete/'.$r->id_cuti_karyawan.'">
<i class="fa fa-times"></i> Delete
</a> ';
 
$rows .='</td>';
 
$rows .='</tr>';
 
++$i;
++$j;
}
 
$paging .= '<li><span class="page-info">Displaying '.($j-1).' Of '.$total.' items</span></i></li>';
$paging .= $this->_paging($total,$limit);
}else{
 
$rows .='<tr>';
$rows .='<td colspan="6">No Data</td>';
$rows .='</tr>';
}
echo json_encode(array('rows'=>$rows,'total'=>$total,'paging'=>$paging));
}
 
private function _paging($total,$limit){
$config = array(
 
'base_url' => base_url().'cuti/data_cuti_karyawan/get_data/',
'total_rows'=> $total,
'per_page' => $limit,
'uri_segment'=> 4
 
);
$this->pagination->initialize($config);
return $this->pagination->create_links();
}
}?>

model
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Data_cuti_karyawan_model extends CI_Model{
 
public function get_data($offset,$limit,$q=''){
$sql = "SELECT a.*,DATE_FORMAT(tgl_cuti, '%d %M %Y') AS tanggal_cuti, b.nama_lengkap,nik, c.tahun, d.keterangan
FROM cuti_karyawan_mutasi a
LEFT JOIN karyawan b ON b.id_karyawan = a.id_karyawan
LEFT JOIN cuti_sisa c ON c.id_cuti_sisa = a.id_cuti_sisa
LEFT JOIN cuti_karyawan d ON d.id_cuti_karyawan = a.id_cuti_karyawan
WHERE 1=1";
if($q){
$sql .=" AND b.nama_lengkap LIKE '%{$q}%'
OR b.nik LIKE '%{$q}%'";
}
$sql .=" ORDER BY a.tgl_cuti DESC";
$ret['total'] = $this->db->query($sql)->num_rows();
$sql .=" LIMIT {$offset},{$limit} ";
$ret['data'] = $this->db->query($sql)->result();
 
return $ret;
}
}?>

Mohon bantuannya ya master 
^:)^
Tagged:
Sign In or Register to comment.