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

Filter data dari Mysql menggunakan Javascript (Combo box)

Siang master,
Saya ada form
image
di form itu uda ke load otomatis data karyawannya, kalau saya masukan nik/nama uda bisa keluar sesuai inputan. Yang jadi masalah kalau saya filter pake Combo box (Jabatan & Departemen) itu caranya belum nemu. Kalau saya ketik nama jabatan di text, datanya bisa muncul. Cuma ga efektif, enakan klo pake combo. Data combonya uda bisa keluar dari database (Jabatan).
Saya pake CI & MySQL.
View

<form role="form" class="form-horizontal">
<label class="col-lg-1 control-label">NIK / Nama</label>
<input type="text" class="form-control" id="search" placeholder="Search..." x-webkit-speech="">
<label class="col-lg-1 control-label">Jabatan</label>
<select name="id_jabatan" id="search" class="form-control">
<option value="">-- Select Jabatan --</option>
<?php foreach($select_jabatan as $pr){?>
<option value="<?php echo $pr->id;?>"><?php echo $pr->jabatan;?></option>
<?php } ?>
</select>
<label class="col-lg-1 control-label">Departemen</label>
<div class="col-lg-3">
<select name="id_departemen" class="form-control">
<option value="">-- Select Departemen --</option>
<?php foreach($select_dept as $pr){?>
<option value="<?php echo $pr->id;?>"><?php echo $pr->nama_departemen;?></option>
<?php } ?>
</select>
<span class="input-group-btn">
<button class="btn btn-primary" id="btn-search"><i class="fa fa-search"></i> Search </button>
</span>
 
 
<table id="data-table" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>NIK</th>
<th>Nama Lengkap</th>
<th>No. Handphone</th>
<th>Jabatan</th>
<th>Status</th>
<th>Sisa Cuti</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
 
function get_data(url,q){
 
if(!url)
url = base_url+'karyawan/report_data_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>
 
</form>


controller

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Report_data_karyawan extends CI_Controller{
 
public function __construct(){
 
parent::__construct();
if(!$this->session->userdata('is_login'))redirect('login');
if(!$this->general->privilege_check(DATA_KARYAWAN,'cetak'))
$this->general->no_access();
$this->session->set_userdata('menu','karyawan');
$this->load->model('report_data_karyawan_model');
}
 
public function index(){
 
$data = array('title'=>'Report Data Karyawan','select_dept'=> $this->_select_dept(),'select_jabatan'=> $this->_select_jabatan());
$this->_render('report_data_karyawan',$data);
 
}
 
private function _render($view,$data = array()){
 
$this->load->view('header',$data);
$this->load->view('sidebar');
$this->load->view($view,$data);
$this->load->view('footer');
}
 
private function _select_dept(){
 
return $this->db->get('s_departemen order by nama_departemen')->result();
}
 
private function _select_jabatan(){
$sql = "SELECT * FROM s_jabatan_user WHERE aktif=1 ORDER BY jabatan";
$ret = $this->db->query($sql)->result();
 
return $ret;
}
 
private function _paging($total,$limit){
 
$config = array(
 
'base_url' => base_url().'karyawan/report_data_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 Report_data_karyawan_model extends CI_Model{
 
private $_table = 'karyawan';
 
public function get_data($offset,$limit,$q=''){
 
$sql = "SELECT a.*, DATE_FORMAT(tgl_masuk, '%d %M %Y') AS tanggal_masuk,
b.nama_status_kerja,
c.jabatan,
IFNULL(SUM(cuti_sisa),0) AS total_cuti
FROM karyawan a
LEFT JOIN s_status_kerja b ON b.id = a.id_status_kerja
LEFT JOIN s_jabatan_user c ON c.id = a.id_jabatan
LEFT JOIN cuti_sisa d ON d.id_karyawan = a.id_karyawan
WHERE is_active='0'
AND (d.tahun IN (YEAR(NOW()),YEAR(NOW())-1) OR d.tahun IS NULL)
";
if($q){
 
$sql .=" AND a.nik LIKE '%{$q}%'
or c.jabatan LIKE '%{$q}%'
OR a.nama_lengkap LIKE '%{$q}%'
";
}
$sql .=" GROUP BY a.id_karyawan";
$sql .=" ORDER BY a.nama_lengkap";
 
$ret['total'] = $this->db->query($sql)->num_rows();
 
$sql .=" LIMIT {$offset},{$limit} ";
 
$ret['data'] = $this->db->query($sql)->result();
 
return $ret;
 
}
}
?>

Mohon bantuannya 
^:)^

Comments

  • belum ada yang bisa bantu ya  :(
  • edited August 2016
    jd maksudnya mau filter nama/nik org berdasarkan jabatan & departemen ? lalu masalahnya kalo pk filter(berdasarkan departement & jabatan) di sql bisa tinggal di tampilannya & kalo hanya 1 filter(jabatan/departement) hasilnya keluar? ?

  • Maap mas uda SOLVE  :D
    Makasih tanggapannya.
Sign In or Register to comment.