| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /wamp/www/simbada_2017/application/modules/gudang/views/ |
Upload File : |
<fieldset>
<legend><?php echo $breadcrumbs;?></legend>
</fieldset>
<div id="grid_container">
<div id="search" class="row">
</div>
<table id="grid"></table>
<div id="pager"></div>
<p> </p><p> </p><p> </p><p> </p><p> </p><p> </p>
</div>
<script>
<?php
$akses = isset($akses) ? $akses : 0;
$canEdit = $akses >= 3;
$canPrint = $akses >= 2;
?>
var grid = $('#grid'), id = last = 0, canEdit = <?php echo $canEdit ? 'true' : 'false'; ?>, initflag = false;
$(document).ready(function() {
params = {
container : $('#search'),
grid : grid,
cols : <?php echo json_encode($grid['fields']); ?>,
}
Search.init(params);
grid.jqGrid({
url:'<?php echo base_url().$modul?>/get_daftar',
editurl:'<?php echo base_url().$modul?>/proses',
datatype:'json',
mtype:'POST',
colNames:['Id','Kode SKPD', 'Nama SKPD', 'Kode Gudang', 'Nama Gudang'],
colModel:[
{name:'id_skpd', hidden:true, editable:true},
{name:'kd_skpd', width:200, editable:true, editoptions:{dataInit:initselect2}},
{name:'nm_skpd', width:380, editable:true, editoptions:{readonly:'true'}},
{name:'kd_gud', width:200, sortable:false, editable:true},
{name:'nm_gud', width:380, sortable:false, editable:true}
],
pager:'#pager',
rownumbers:true,
viewrecords:true,
gridview:true,
shrinkToFit:false,
autowidth:true,
height:300,
/* rowNum:1000000,
scroll:true,
rownumbers:true,
viewrecords:true,
gridview:true,
shrinkToFit:false,
autowidth:true,
height:'400', */
recordtext:'{2} baris',
onSelectRow: function(id){
if(id && id!==last){
$(this).restoreRow(last);
last=id;
}
},
ondblClickRow:edit_row,
});
grid.jqGrid('bindKeys', {"onEnter": edit_row});
grid.jqGrid( 'navGrid', "#pager", {
add: canEdit,
addtext: 'Tambah',
addfunc: add_row,
edit: canEdit,
edittext: 'Ubah',
editfunc: edit_row,
del: canEdit,
deltext: 'Hapus',
delfunc: del_row,
search: false,
searchtext: 'Cari',
refresh: true,
refreshtext: 'Refresh',
},{},{},{},{});
<?php
if ($canPrint)
{
?>
grid.jqGrid().navSeparatorAdd('#pager')
.navButtonAdd('#pager',{
caption:'Cetak',
onClickButton: function(){ preview({"tipe":"daftar"}, grid)},
title:'Cetak Daftar',
buttonicon:'ui-icon-print',
position:'last'
});
<?php
}
?>
});
function add_row(){
if (!canEdit) return;
addparam = {
rowID : --id,
initdata: {aktif: 1},
position :"last",
addRowParams : {
keys : true,
aftersavefunc: aftersavefunc,
beforeSaveRow: beforesavefunc,
afterrestorefunc: afterrestorefunc,
oneditfunc: oneditfunc,
successfunc: successfunc,
errorfunc: errorfunc,
restoreAfterError: false,
}
}
$(this).jqGrid('addRow', addparam);
}
function edit_row(id){
if (!canEdit) return;
pejabat_event = true;
editparam = {
keys : true,
aftersavefunc: aftersavefunc,
beforeSaveRow: beforesavefunc,
afterrestorefunc: afterrestorefunc,
oneditfunc: oneditfunc,
successfunc: successfunc,
errorfunc: errorfunc,
restoreAfterError: false,
}
$(this).jqGrid('editRow', id, editparam);
last = id;
return false;
}
function del_row(id){
if (!canEdit) return;
var grid = $(this),
question = 'Hapus Gudang dari daftar ?';
confirmation(question).then(function(answer){
if (!answer) return;
$.ajax({
url: '<?php echo base_url().$modul?>/hapus',
type: "post",
dataType: "json",
data: { id: id},
success: function(res){
if (res.isSuccess) show_info(res.message, 'Sukses');
else show_error(res.message, 'Gagal');
if(res.isSuccess == true) {
grid.jqGrid('delRowData', id);
}
},
});
});
}
function aftersavefunc(id, resp){
oresp = JSON.parse(resp.responseText);
newid = oresp.id;
if (oresp.isSuccess){
show_info(oresp.message, 'Sukses');
if (newid !== id){
data = $(this).jqGrid('getRowData', id);
data.id = newid;
$(this).jqGrid('addRowData', newid, data, 'after', id);
$(this).jqGrid('delRowData', id);
$(this).jqGrid('resetSelection')
$(this).jqGrid('setSelection', newid)
last = id;
}
}
else {
show_error(oresp.message, 'Gagal');
}
$(this).focus();
}
function beforesavefunc(opt, id){
kd_skpd = $('#'+id+'_kd_skpd').select2('val');
nm_skpd = $('#'+id+'_nm_skpd').val();
kd_gud = $('#'+id+'_kd_gud').val();
nm_gud = $('#'+id+'_nm_gud').val();
if (kd_skpd == '' || nm_skpd == '' || kd_gud == '' || nm_gud == '') {
show_warning('Silahkan melengkapi semua isian', 'Perhatian');
return false;
}
/* remove select2 */
$('#'+id+'_kd_skpd').select2('destroy');
}
function oneditfunc(id){
$('#'+id+'_kd_skpd').select2('focus');
initflag = true;
}
function successfunc(resp){
oresp = JSON.parse(resp.responseText);
return oresp.isSuccess;
}
function errorfunc(id, resp){
oresp = JSON.parse(resp.responseText);
show_error(oresp.message, 'Gagal');
}
function afterrestorefunc(){
$(this).focus();
}
function initselect2(el){
var oid = el.id;
$(el).select2({
minimumInputLength: 0,
ajax: {
url: "<?php echo base_url()?>pilih/get_select2_skpd",
type: 'POST',
dataType: 'json',
quietMillis: 200,
data: function(term){
return {'q': term}
},
results: function(data) {
return {results: data.results}
},
},
placeholder: 'Pilih SKPD',
allowClear: true,
openOnEnter: false,
dropdownAutoWidth : true,
initSelection: function(element, callback){
var data = {'text': element.val()};
callback(data);
},
formatResult: formatSelect2
});
$(el).on('change', function(e){
var idx = e.target.id;
// apply selection to grid element
var pos = idx.indexOf('kd_skpd');
if ( pos > -1){
var pre = idx.substring(0, pos);
$('#'+pre+'id_skpd').val(e.added ? e.added.id : '');
$('#'+pre+'kd_skpd').val(e.added ? e.added.kode : '');
$('#'+pre+'nm_skpd').val(e.added ? e.added.nama : '');
//$(e.target).val(e.added ? e.added.text : '');
return false;
}
e.stopPropagation();
});
$(el).on('select2-removed', function(e){
var ele = [
{id: "id_skpd", kode: "kd_skpd", nama: "nm_skpd"},
];
var idx = e.target.id;
// apply selection to grid element
var pos = idx.indexOf('kd_skpd');
if ( pos > -1){
var pre = idx.substring(0, pos);
$('#'+pre+'id_skpd').val('');
$('#'+pre+'kd_skpd').val('');
$('#'+pre+'nm_skpd').val('');
return false;
}
e.stopPropagation();
});
}
formatSelect2 = function(res){
return '<div><strong>' + res.kode + '</strong></div><div style="border-bottom:1px solid #ccc">' + res.nama + '</div>';
}
</script>