<script type="text/javascript">  
theight=$( document ).height()-50; 
function setdg(){
	$('#dg').datagrid({  	
		width:600,
		height:theight,
		toolbar:"#toolbar",
		fitColumns:true,
		rownumbers:true,		
		pagination:true,
		pageSize:100,
		pageList:[100,200,300,400,500],
		columns:[[  
			{field:'kd_mtgrup',title:'Kode',width:100},
			{field:'nm_mtgrup',title:'Nama',width:250}
		]],
		url: '<?=site_url('mtgrup/grid'); ?> '
	});
}

function cari(q){
	$('#dg').datagrid({
		queryParams:{q:q}		
	});
}

var url;
function tambah(){
	$('#dlg').dialog('open').dialog('setTitle','Tambah <?=$title?>');
	$('#fm').form('clear');
	url = '<?=site_url('mtgrup/getform/add'); ?>';
}

function ubah(){
	var row = $('#dg').datagrid('getSelected');
	$('#empl_id').combogrid({  
		editable:false  
    });  
	if (row){
		$('#dlg').dialog('open').dialog('setTitle','Ubah <?=$title?>');
		$('#fm').form('load',row);
		url = '<?=site_url('mtgrup/getform/edit'); ?>';
	}
}

function simpan(){
	$('#fm').form('submit',{
		url: url,
		onSubmit: function(){				
			return $(this).form('validate');
		},
		success: function(result){
			//alert(result);
			var result = eval('('+result+')');
			if (result.success){
				$('#dlg').dialog('close');		// close the dialog
				$('#dg').datagrid('reload');	// reload the mtgrup data
				$.messager.show({
					title: 'Info',
					msg: result.msg
				});
			} else {
				$.messager.show({
					title: 'Error',
					msg: result.msg
				});
			}
		}
	});
}

function hapus(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$.messager.confirm('Confirm','Apakah anda yakin akan menghapus data ini?',function(r){
			if (r){
				$.post('<?=site_url(); ?>mtgrup/del',{id:row.id},function(result){
					var result = eval('('+result+')');
					if (result.success){
						$('#dg').datagrid('reload');	// reload the mtgrup data
						$.messager.show({
							title: 'Info',
							msg: result.msg
						});
					} else {
						$.messager.show({	// show error message
							title: 'Error',
							msg: result.msg
						});
					}
				});
			}
		});
	}
}

function toprint(){
	var opts = $('#dg').datagrid('options');
	q=$("#q").val();
	
	var win = window.open('<?= site_url()?>mtgrup/cetak?q='+q+'&page='+opts.pageNumber+'&rows='+opts.pageSize,'Popup','toolbar=no, location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
	win.print();
}

function toxls(){
	var opts = $('#dg').datagrid('options');
	txtcari=$("#txtcari").val();
	openurl('<?=site_url();?>mtgrup/excel?q='+q+'&page='+opts.pageNumber+'&rows='+opts.pageSize);
}

function topdf(){
	openurl("<?=site_url();?>mtgrup/topdf");
}



function insert_nama(row){
	$("#nama").val(row.nama);
}
</script>	