<div style="height:40px;">
	<button id="btngetitem" >Get Item List</button>
 	<button id="btnupdateinsert" >Update/Insert Data</button>
</div>
<table id="tbl_barang"></table> <div id="ptbl_barang"></div>
<script type="text/javascript">
    
    $(document).ready(function(){

		$("#btngetitem").button().click(function(){
			$("#frmitemlistdlg").load('<?php echo base_url().'pasi_settings/ct_barang/view_barang_itemlist'; ?>',  {parmeter:'parameter'}, function() {
				$("#frmitemlistdlg").dialog({
					modal:true,
					width : 694,
					height : 499,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmitemlistdlg').dialog("destroy"); 
					    $(".frmitemlistdlg_cl").remove(); 
					    $("body").append('<div id="frmitemlistdlg" title="ITEM LIST" class="frmitemlistdlg_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		});
		$("#btnupdateinsert").button().click(function(){
			var id = jQuery("#tbl_barang").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_barang").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data={
				idx:ret.id,
				kd_brg:ret.kd_brg,
				item_no:ret.item_no,
				part_no:ret.part_no,
				unit:ret.unit
			};			
			
			$("#frmbarangupdate_dlg").load('<?php echo base_url().'pasi_settings/ct_barang/view_barang_update'; ?>',  form_data, function() {
				$("#frmbarangupdate_dlg").dialog({
					modal:true,
					width : 340,
					height : 300,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmbarangupdate_dlg').dialog("destroy"); 
					    $(".frmbarangupdate_dlg_cl").remove(); 
					    $("body").append('<div id="frmbarangupdate_dlg" title="Nama Barang" class="frmbarangupdate_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		
		
		});
		
		jQuery("#tbl_barang").jqGrid({
			url:'<?php echo base_url().'pasi_settings/ct_barang/loadData'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['id', 'kd_brg','item_no','part_no','unit','create_date','create_by','update_date','update_by','Status'],
			colModel:[
				{name:'id_master_brg',index:'id_master_brg', width:60, hidden:true},
				{name:'kd_brg',index:'kd_brg', width:72},
				{name:'item_no',index:'item_no', width:313},
				{name:'part_no',index:'part_no', width:230, hidden:false},
				{name:'unit',index:'unit', width:80,hidden:false},
				{name:'create_date',index:'create_date', width:80,hidden:false},
				{name:'create_by',index:'create_by', width:80,hidden:false},
				{name:'update_date',index:'update_date', width:80,hidden:false},
				{name:'update_by',index:'update_by', width:80,hidden:false},
				{name:'status',index:'status', width:90,hidden:false},
				],
			rowNum:15,
			rowList:[15,25,35],
			pager: '#ptbl_barang',
			sortname: 'id_master_brg',
			viewrecords: true,
			sortorder: "asc",
			width: 985,
			height:300,
			jsonReader: { repeatitems : false },
			caption:"Data Master Kode Barang",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
						
			},			
			gridComplete: function(){
				
			},
		}); 
			
                        
		jQuery("#tbl_barang").jqGrid('navGrid','#ptbl_barang',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_barang").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		

	});
		  	
</script>
<div id="frmbarangupdate_dlg" title="Nama Barang" class="frmbarangupdate_dlg_cl"></div>
<div id="frmitemlistdlg" title="ITEM LIST" class="frmitemlistdlg_cl"></div>



	
	