ITeye博客

jqgrid宽度高度自适应

openstudy · 2011-04-13 11:31 · jquery · Web前端 · Markdown

<style>
	<!--
	.zebra-striped {
		background: #efefff 50% 50% repeat-x;
	}
	-->
</style>

<script language='javascript'><!--
	$(function() {
		$("#gridTable").jqGrid({
			url:'userData.action',
			datatype: "json",
			autowidth: false,
			altRows: true,
			altclass: "zebra-striped",
			colNames:,
			colModel:,
			sortname:'userId',
			sortorder:'asc',
			viewrecords:true,
			rowNum: 20,
			rowList: ,
			jsonReader:{
				repeatitems : false,
				id: "userId",
				total: "totalPageCount",
				page: "pageNumber",
				records: "totalRecordCount"
			},
			toolbar: ,
			pager:"#gridPager",
			rownumbers: true,
			//multiselect: true,
			pagerpos: "left"
		}).navGrid('#gridPager',{edit:false,add:false,del:false, refresh:false, search:false});

		doResize();
	});
	
	var t=document.documentElement.clientWidth;  
	window.onresize = function(){  
		if(t != document.documentElement.clientWidth){
			t = document.documentElement.clientWidth;
			doResize();
		}
	}

	function doResize() {
		var ss = getPageSize();
		$("#gridTable").jqGrid('setGridWidth', ss.WinW-10).jqGrid('setGridHeight', ss.WinH-100);
    }

	function getPageSize() {
		//http://www.blabla.cn/js_kb/javascript_pagesize_windowsize_scrollbar.html
		var winW, winH;
		if(window.innerHeight) {// all except IE
			winW = window.innerWidth;
			winH = window.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
			winW = document.documentElement.clientWidth;
			winH = document.documentElement.clientHeight;
		} else if (document.body) { // other
			winW = document.body.clientWidth;
			winH = document.body.clientHeight;
		}  // for small pages with total size less then the viewport  
		return {WinW:winW, WinH:winH};
	}
	
	//http://www.wsria.com/archives/1147有另一种算法
--></script>

评论(4)

  1. #4 楼 · atgoingguoat · 2014-05-27 09:36

    感谢!!! 不错。 我复制就能用。 哈哈。

  2. #3 楼 · fover1985 · 2012-11-12 17:51

    这里有我的自适应宽度的一个解决方法: http://blog.csdn.net/fover717/article/details/8170436

  3. #2 楼 · A21k · 2011-12-24 14:22

    :evil:

  4. #1 楼 · A21k · 2011-12-24 14:22

    <>****

    
    

评论功能维护中,当前仅展示历史评论。