---
title: "Ext Grid表格的自动宽度及高度的实现"
author: "Seraph115"
date: "2008-08-06T18:05:53Z"
tags: []
categories: ["Web前端"]
slug: "ext-grid"
draft: false
lastmod: "2009-05-05T11:57:04Z"
id: 225157
url: "https://seraph115.iteye.com/blog/225157"
---

希望Ext的表格能自适应外层的div大小，但Ext的Grid构造函数的width、height项不支持100%的设置方式，所以改用以下方式初始化Grid：

<span style="color:red">width: Ext.get("content").getWidth(),
height: Ext.get("content").getHeight(),</span>

<div id="content">
    <div id="grid-example"></div>
<div>

#content {
	width: 100%;
	height: 100%;
}

完整js代码：

// create the Grid
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: ,
        stripeRows: true,
        width: Ext.get("content").getWidth(),
        height: Ext.get("content").getHeight(),
		addClass:"grid",
		tbar: ,
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: store,
            displayInfo: true,
            displayMsg: '当前显示记录 {0} - {1} 总条数 {2}',
            emptyMsg: '无记录'
        })
    });