当前位置: 代码迷 >> Web前端 >> Ext 三中grid的autoHeight的bug fixing: maxHeight
  详细解决方案

Ext 三中grid的autoHeight的bug fixing: maxHeight

热度:618   发布时间:2012-08-22 09:50:35.0
Ext 3中grid的autoHeight的bug fixing: maxHeight

? ? 在Ext3的grid中,autoHeight有个遗留的bug,不知道后续有没有被修掉。这个bug是说max height设定的值不起作用。也就是说,autoHeight的情况下,虽然设定了max height的值,但是当grid的height的值超过了max height,还是会继续增加,而不会已出现滚动条形式出现。由于我们的开发基于版本3,不能期待后续的版本了。

? ?在查找了一些资料,并修正了存在的bug之后,终于可以使得autoHeight的属性正常被使用。

? ?首先,复写gridView中的layout方法:

?? layout : function(initial) {

		if (!this.mainBody) {
			return; // not
			rendered
		}

		var grid = this.grid, gridEl = grid.getGridEl(), gridSize = gridEl
				.getSize(true), gridWidth = gridSize.width, gridHeight = gridSize.height, scroller = this.scroller, scrollStyle, headerHeight, scrollHeight;

		if (gridWidth < 20 || gridHeight < 20) {
			return;
		}

		if (grid.autoHeight) {
			scrollStyle = scroller.dom.style;
			if (Ext.isNumber(grid.maxHeight) && gridHeight >= grid.maxHeight) {
				gridHeight = grid.maxHeight;
				this.el.setSize(gridWidth, gridHeight);

				headerHeight = this.mainHd.getHeight();
				scrollHeight = gridHeight - headerHeight;
				scroller.setSize(gridWidth, scrollHeight);

				scrollStyle.overflow = '';
				scrollStyle.position = '';
			} else {
				this.el.setSize();
				scroller.setSize();

				scrollStyle.overflow = 'visible';
				if (Ext.isWebKit) {
					scrollStyle.position = 'static';
				}
			}
		} else {
			this.el.setSize(gridWidth, gridHeight);

			headerHeight = this.mainHd.getHeight();
			scrollHeight = gridHeight - headerHeight;

			scroller.setSize(gridWidth, scrollHeight);

			if (this.innerHd) {
				this.innerHd.style.width = (gridWidth) + "px";
			}
		}

		if (this.forceFit || (initial === true && this.autoFill)) {
			if (this.lastViewWidth != gridWidth) {
				this.fitColumns(false, false);
				this.lastViewWidth = gridWidth;
			}
		} else {
			this.autoExpand();
			this.syncHeaderScroll();
		}

		this.onLayout(gridWidth, scrollHeight);
	}

?其次,每次我们对一个grid进行手动add之后,都要synSize一下这个grid:

?

	_synsizeGridWhenAddData : function(grid) {
				grid.store.on("add", function(tis, records, opt) {
							grid.syncSize();
						}, this);
			},
  相关解决方案