<style>
.flexigrid thead tr th{
	padding-right: 0.2mm;
}
.flexigrid thead tr td{
	padding-right: 0.1mm;
}
</style>

<?php
$idDiv = $this->data->mode.'_grid';
$pk = $this->data->set->dBasePk[0];
$sort = 'asc';
if(!empty($this->data->set->sort)){
	$sort = $this->data->set->sort;
}
if(!empty($this->data->set->pkSort)){
	$pk = $this->data->set->pkSort;
}

if(empty($_GET['ctrl'])){
	$cls = $this->getParameter['controller'];
	$_SESSION['dataSetting'][$cls] = $this->data->set->set;
	$_SESSION['dataSetting'][$cls]->database = $this->config['dbConnection.dbServer'];
}

$fil2020 = '';
if(!empty($_POST['filre'])){
	foreach($_POST['filre'] as $k => $r){
		$r = trim($r);
		if(!empty($r)){
			if(!empty($fil2020)){
				$fil2020.= ';';
			}
			$fil2020.= $k.'=>'.$r;
		}
	}
}

if(!empty($_GET['_typeBrowse'])){
	$this->data->mode = $_GET['_typeBrowse'];
}

?>

<form method="POST" id="_postGrid2020">
	<div id="<?php echo $idDiv ?>"></div>
</form>
<input type="hidden" id="_typeBrowse" value="<?php echo $this->data->mode ?>">
<input type="hidden" id="filterGrid2020" value="<?php echo $fil2020 ?>">

<script type='text/javascript'>
$(document).ready(function(){
	
	_widthGrid2 = 930;
	/* screen.width is the physical device width, not the visible
	   viewport — on mobile browsers those can differ a lot and left
	   the grid trying to render at a near-zero width. window.innerWidth
	   is the actual usable viewport. */
	_widthSecr2 = window.innerWidth - 20;
	if(_widthSecr2 < _widthGrid2){
		_widthGrid2 = _widthSecr2;
	}
	/* Never let it collapse below a width the colModel can actually
	   fit in — below this, let it render at min-width and scroll
	   horizontally instead (see mobile-rasio-form.css) rather than
	   squeezing every column into illegibility. */
	if(_widthGrid2 < 320){
		_widthGrid2 = 320;
	}
		
	$('#_cls').val("<?php echo $cls ?>");
	$("#<?php echo $idDiv ?>").flexigrid({
		url : 'Basic/grid2020/&ctrl=<?php echo $cls ?>',
		dataType : 'xml',
		colModel : [ 
					{display : ' ',		name : 'a.nojnl',	width : 30,	sortable : true, align : 'center'}, 
					{display : 'No',	name : 'a.nojnl',	width : 30,	sortable : true, align : 'center'}, 
					<?php 
					foreach($this->data->set->grid->attr as $row){  
						if(empty($row['sort'])){
							$row['sort'] = true;
						}
					?>
						{display : '<?php echo $row['label'] ?>',name : '<?php echo $row['attr'] ?>',	width : <?php echo $row['width'] ?>,	sortable : <?php echo $row['sort'] ?>, align : '<?php echo $row['align'] ?>'}, 
					<?php } ?>
					],
		title: '<?php echo $this->data->set->modul ?>',
		sortname : "<?php echo $pk ?>",
		sortorder : "<?php echo $sort ?>",
		usepager : true,
		useRp : true,
		rp : 50,
		showTableToggleBtn : true,
		width : _widthGrid2,
		height : 270,
		buttons :[
					{
						name : '<input type="button" alt="Search" class="gridcari" value="Search" id="cariGrid2020">', 
						bclass : 'exportToPdf ' 
					},
					{
						name : '<span id="_loadingGrid2020"></span>', 
						bclass : 'exportToPdf ' 
					},
				],
	});
	
	_loadPopUpTop = false;
	makeCariGrid2020 = function(){
		_loadT = "&urut=<?php echo $_GET['urut'] ?>";
		_loadT+= "&_typeBrowse="+$('#_typeBrowse').val();

		_lastNo = $('.urut_<?php echo $_GET['urut'] ?>').attr('id');
		_hed 	= $('#'+_lastNo).attr('name');
		if(_hed != undefined){
			_load = $('#'+_lastNo).attr('load');
			if(_load != undefined){
				_load = _load.split(",");
				for(_i = 0; _i < _load.length; _i++){
					_loadT+= "&"+_load[_i]+'='+$('#'+_load[_i]).val();
				}
			}
		}
		
		$('#_loadingGrid2020').html('Loading...');
		_url = "<?php echo $this->baseUrl.$cls.'/data/' ?>"+_loadT;
		if(_loadPopUpTop != false){
			_loadPopUpTop.abort();
		}
		
		_loadPopUpTop = $.ajax({
		type: 'POST',
			url: _url,
			data: $('#_postGrid2020').serialize(),
			success: function(data) {
				$('#apankFormContent').html(data);
			}
		})
	}
})
</script>
