Ext DatePicker大小自适应

不知道为什么Ext的DatePicker明明是有height和width配置选项的,可是写上就是不见变化。用FireBug看了下渲染的html代码发现无论如何它都自动加上了行内样式width为175px,看了它的源码也没发现在哪加的。
自己动手强行改吧,监听DatePicker的render事件,然后自己重新处理样式。

var p = new Ext.Panel({
	width: 800,
	height: 500,
	renderTo: Ext.getBody(),
	items: new Ext.DatePicker({
		//不加这个宽度不会变
		style: 'width:100%;height:100%',
		listeners: {
			'render': function(dp){
				//取得DatePicker的DOM节点的第一个子节点
				var outerTable = dp.el.dom.firstChild;
				//取得DatePicker的顶部导航条
				var tbar = outerTable.firstChild.childNodes[0];
				//取得DatePicker的主体
				var main = outerTable.firstChild.childNodes[1];
				//取得DatePicker底部工具条
				var bbar = outerTable.firstChild.childNodes[2];
 
				var innerTable = main.firstChild.firstChild;
				//
				var thead = innerTable.firstChild;
				//使用行内样式修改
				outerTable.style.width = '100%';
				outerTable.style.height = '100%';
				//以下为解决DatePicker变形
				tbar.style.height = '30px';
				bbar.style.height = '30px';
				innerTable.style.height = '100%';
				thead.firstChild.style.height = '20px';
			}
		}
	})	
});

除非另有声明,本站遵循【署名-非商业性使用-相同方式共享 3.0 共享协议】授权。

转载原创文章请注明,转载自:Neeke[http://www.ineeke.com]

本文链接: http://www.ineeke.com/archives/ext-datepicker-size-of-the-adaptive/

2009年12月17日 | 归档于 ExtJS | 1 条评论
  1. 2009年12月18日 16:23 | #1

    收藏下。多谢。。。

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
n:-zy n:-zr n:-zan n:-xf n:-wx n:-tz n:-tt n:-ts n:-sy n:-st n:-ss n:-sk n:-qd n:-pz n:-lh n:-kun n:-ku n:-hx n:-hd n:-gt n:-gg n:-bz

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!