<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<link rel="stylesheet" href="${contextPath}/static/assets/css/jquery-ui.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/ui.jqgrid.css" />

<div class="row">
	<div class="col-xs-12">
		<table id="grid-table"></table>
		<div id="grid-pager"></div>
		<script type="text/javascript">
			var $path_base = "${contextPath}/static";//in Ace demo this will be used for editurl parameter
		</script>
	</div><!-- /.col -->
</div><!-- /.row -->

<!-- page specific plugin scripts -->
<script type="text/javascript">
	var myGrid = null;
	var scripts = [ null, "${contextPath}/static/assets/js/jqGrid/jquery.jqGrid.js", "${contextPath}/static/assets/js/jqGrid/i18n/grid.locale-cn.js", null ];
	$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
		// inline scripts related to this page
     	jQuery(function($) {
     		var grid_selector = "#grid-table";
     		var pager_selector = "#grid-pager";

     		// resize to fit page size
     		$(window).on('resize.jqGrid', function() {
     			$(grid_selector).jqGrid('setGridWidth', $(".page-content").width());
     		})
     		// resize on sidebar collapse/expand
     		var parent_column = $(grid_selector).closest('[class*="col-"]');
     		$(document).on('settings.ace.jqGrid', function(ev, event_name, collapsed) {
     			if (event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed') {
     				// setTimeout is for webkit only to give time for DOM changes and then redraw!!!
     				setTimeout(function() {
     					$(grid_selector).jqGrid('setGridWidth', parent_column.width());
     				}, 0);
     			}
     		});

     		myGrid = jQuery(grid_selector).jqGrid({
     			subGrid : false,
     			url : "${contextPath}/sys/ssdbOnline/getCustomerContactInfos",
     			datatype : "json",
     			height : '99%',
     			colModel : [  {
     				name : 'id',
     				label : '',
     				width : 80,
       				viewable:false,
       				hidden : true,
     			},{
     				name : 'name',
     				label : '姓名',
     				width : 120,
     			},{
     				name : 'mobile',
     				label : '电话',
     				width : 120,
     			},{
     				name : 'createDate',
     				label : '创建时间',
     				width : 100,
     			}],
     			//scroll : 1, // set the scroll property to 1 to enable paging with scrollbar - virtual loading of records
     			sortname : "createDate",
     			sortorder : "desc",
     			viewrecords : true,
     			rowNum : 10,
     			rowList : [ 10, 20, 30 ],
     			pager : pager_selector,
     			altRows : true,
       			multiselect : true,
     			loadComplete : function() {
     				var table = this;
     				setTimeout(function(){
     					updatePagerIcons(table);
     					enableTooltips(table);
     				}, 0);
     			},
     		});

     		$(window).triggerHandler('resize.jqGrid');// trigger window resize to make the grid get the correct size
     		
     		jQuery(grid_selector).jqGrid('navGrid', pager_selector, {
     			edit : false,
       			editicon : 'ace-icon fa fa-pencil blue',
       			add : false,
       			addicon : 'ace-icon fa fa-plus-circle purple',
       			del : false,
       			delicon : 'ace-icon fa fa-trash-o red',
       			search : false,
       			searchicon : 'ace-icon fa fa-search orange',
       			refresh : false,
       			refreshicon : 'ace-icon fa fa-refresh blue',
       			view : false,
     		});

     		// replace icons with FontAwesome icons like above
     		function updatePagerIcons(table) {
     			var replacement = {
     				'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140',
     				'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140',
     				'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140',
     				'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140'
     			};
     			$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function() {
     				var icon = $(this);
     				var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

     				if ($class in replacement)
     					icon.attr('class', 'ui-icon ' + replacement[$class]);
     			});
     		}

     		function enableTooltips(table) {
     			$('.navtable .ui-pg-button').tooltip({
     				container : 'body'
     			});
     			$(table).find('.ui-pg-div').tooltip({
     				container : 'body'
     			});
     		}

     		// var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

     		$(document).one('ajaxloadstart.page', function(e) {
     			$(grid_selector).jqGrid('GridUnload');
     			$('.ui-jqdialog').remove();
     		});
     	});
	});
</script>