From 6c386ebd1158edc7cf79fe9c4bc2582c484099b0 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 6 Jun 2017 12:10:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 107 ++++++++++++++++++++--------- bi/core.js | 7 +- docs/base.js | 107 ++++++++++++++++++++--------- docs/core.js | 7 +- src/base/table/table.collection.js | 66 ++++++++++++------ src/base/table/table.grid.js | 41 +++++++---- src/core/widget.js | 7 +- 7 files changed, 231 insertions(+), 111 deletions(-) diff --git a/bi/base.js b/bi/base.js index 6df42bb8b..9aa2a6024 100644 --- a/bi/base.js +++ b/bi/base.js @@ -29054,11 +29054,26 @@ BI.CollectionTable = BI.inherit(BI.Widget, { return this.options.isNeedFreeze ? this.options.freezeCols.length : 0; }, + _getFreezeHeaderHeight: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return 0; + } + return o.header.length * o.headerRowSize; + }, + + _getActualItems: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return o.header.concat(o.items); + } + return o.items; + }, + _populateScrollbar: function () { var o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; - var freezeColLength = this._getFreezeColLength(); + summaryColumnSizeArray = []; BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { totalLeftColumnSize += size; @@ -29072,8 +29087,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; } }); - this.topScrollbar.setContentSize(o.items.length * o.rowSize); - this.topScrollbar.setSize(this._height - o.header.length * o.headerRowSize); + this.topScrollbar.setContentSize(this._getActualItems().length * o.rowSize); + this.topScrollbar.setSize(this._height - this._getFreezeHeaderHeight()); this.topScrollbar.setPosition(this.bottomRightCollection.getScrollTop()); this.topScrollbar.populate(); @@ -29088,7 +29103,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { this.rightScrollbar.populate(); var items = this.scrollBarLayout.attr("items"); - items[0].top = o.header.length * o.headerRowSize; + items[0].top = this._getFreezeHeaderHeight(); items[1].top = this._height; items[2].top = this._height; items[2].left = regionSize; @@ -29099,8 +29114,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _populateTable: function () { var self = this, o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; - var freezeColLength = this._getFreezeColLength(); + summaryColumnSizeArray = []; BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { totalLeftColumnSize += size; @@ -29116,13 +29130,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, { }); var otlw = regionSize; - var otlh = o.header.length * o.headerRowSize; + var otlh = this._getFreezeHeaderHeight(); var otrw = this._width - regionSize; - var otrh = o.header.length * o.headerRowSize; + var otrh = this._getFreezeHeaderHeight(); var oblw = regionSize; - var oblh = this._height - o.header.length * o.headerRowSize; + var oblh = this._height - otlh; var obrw = this._width - regionSize; - var obrh = this._height - o.header.length * o.headerRowSize; + var obrh = this._height - otrh; var tlw = otlw + this._scrollBarSize; var tlh = otlh + this._scrollBarSize; @@ -29166,9 +29180,9 @@ BI.CollectionTable = BI.inherit(BI.Widget, { var items = this.contextLayout.attr("items"); items[1].left = regionSize; - items[2].top = o.header.length * o.headerRowSize; + items[2].top = this._getFreezeHeaderHeight(); items[3].left = regionSize; - items[3].top = o.header.length * o.headerRowSize; + items[3].top = this._getFreezeHeaderHeight(); this.contextLayout.attr("items", items); this.contextLayout.resize(); @@ -29184,8 +29198,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { }; run(this.topLeftItems, o.header, leftHeader); run(this.topRightItems, o.header, rightHeader); - run(this.bottomLeftItems, o.items, leftItems); - run(this.bottomRightItems, o.items, rightItems); + run(this.bottomLeftItems, this._getActualItems(), leftItems); + run(this.bottomRightItems, this._getActualItems(), rightItems); this.topLeftCollection._populate(leftHeader); this.topRightCollection._populate(rightHeader); @@ -29196,13 +29210,23 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _digest: function () { var o = this.options; var freezeColLength = this._getFreezeColLength(); - this.topLeftItems = this._serialize(o.header, 0, freezeColLength, o.headerRowSize, o.columnSize, o.mergeCols); - this.topRightItems = this._serialize(o.header, freezeColLength, o.columnSize.length, o.headerRowSize, o.columnSize, true); - this.bottomLeftItems = this._serialize(o.items, 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols); - this.bottomRightItems = this._serialize(o.items, freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols); + //如果表头位置不够,取消表头冻结 + if (this._getFreezeHeaderHeight() <= 0) { + this.topLeftItems = []; + this.topRightItems = []; + this.bottomLeftItems = this._serialize(this._getActualItems(), 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols, BI.range(o.header.length)); + this.bottomRightItems = this._serialize(this._getActualItems(), freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols, BI.range(o.header.length)); + } else { + this.topLeftItems = this._serialize(o.header, 0, freezeColLength, o.headerRowSize, o.columnSize, o.mergeCols); + this.topRightItems = this._serialize(o.header, freezeColLength, o.columnSize.length, o.headerRowSize, o.columnSize, true); + this.bottomLeftItems = this._serialize(o.items, 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols); + this.bottomRightItems = this._serialize(o.items, freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols); + } }, - _serialize: function (items, startCol, endCol, rowHeight, columnSize, mergeCols) { + _serialize: function (items, startCol, endCol, rowHeight, columnSize, mergeCols, mergeRows) { + mergeCols = mergeCols || []; + mergeRows = mergeRows || []; var self = this, o = this.options; var result = [], cache = {}, preCol = {}, preRow = {}, map = {}; var summaryColumnSize = []; @@ -29252,7 +29276,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { } cache[i][j] = cols[j]; map[i][j] = {}; - if (mergeCols === true || mergeCols.indexOf(j) > -1) { + if (mergeCols === true || mergeCols.indexOf(j) > -1 || mergeRows === true || mergeRows.indexOf(i) > -1) { if (i === 0 && j === startCol) { createOneEl(0, startCol); } else if (j === startCol && i > 0) { @@ -29838,11 +29862,26 @@ BI.GridTable = BI.inherit(BI.Widget, { return this.options.isNeedFreeze ? this.options.freezeCols.length : 0; }, + _getFreezeHeaderHeight: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return 0; + } + return o.header.length * o.headerRowSize; + }, + + _getActualItems: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return o.header.concat(o.items); + } + return o.items; + }, + _populateScrollbar: function () { var o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; - var freezeColLength = this._getFreezeColLength(); + summaryColumnSizeArray = []; BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { totalLeftColumnSize += size; @@ -29856,8 +29895,8 @@ BI.GridTable = BI.inherit(BI.Widget, { summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; } }); - this.topScrollbar.setContentSize(o.items.length * o.rowSize); - this.topScrollbar.setSize(this._height - o.header.length * o.headerRowSize); + this.topScrollbar.setContentSize(this._getActualItems().length * o.rowSize); + this.topScrollbar.setSize(this._height - this._getFreezeHeaderHeight()); this.topScrollbar.setPosition(Math.min(this.bottomLeftGrid.getScrollTop(), this.bottomRightGrid.getScrollTop())); this.topScrollbar.populate(); @@ -29872,7 +29911,7 @@ BI.GridTable = BI.inherit(BI.Widget, { this.rightScrollbar.populate(); var items = this.scrollBarLayout.attr("items"); - items[0].top = o.header.length * o.headerRowSize; + items[0].top = this._getFreezeHeaderHeight(); items[1].top = this._height; items[2].top = this._height; items[2].left = regionSize; @@ -29906,7 +29945,7 @@ BI.GridTable = BI.inherit(BI.Widget, { var o = this.options; var freezeColLength = this._getFreezeColLength(); var leftItems = [], rightItems = []; - BI.each(o.items, function (i, cols) { + BI.each(this._getActualItems(), function (i, cols) { leftItems[i] = []; rightItems[i] = []; BI.each(cols, function (j, col) { @@ -29927,7 +29966,7 @@ BI.GridTable = BI.inherit(BI.Widget, { _populateTable: function () { var self = this, o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; + summaryColumnSizeArray = []; var freezeColLength = this._getFreezeColLength(); BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { @@ -29944,13 +29983,13 @@ BI.GridTable = BI.inherit(BI.Widget, { }); var otlw = regionSize; - var otlh = o.header.length * o.headerRowSize; + var otlh = this._getFreezeHeaderHeight(); var otrw = this._width - regionSize; - var otrh = o.header.length * o.headerRowSize; + var otrh = this._getFreezeHeaderHeight(); var oblw = regionSize; - var oblh = this._height - o.header.length * o.headerRowSize; + var oblh = this._height - otlh; var obrw = this._width - regionSize; - var obrh = this._height - o.header.length * o.headerRowSize; + var obrh = this._height - otrh; var tlw = otlw + this._scrollBarSize; var tlh = otlh + this._scrollBarSize; @@ -30003,9 +30042,9 @@ BI.GridTable = BI.inherit(BI.Widget, { var items = this.contextLayout.attr("items"); items[1].left = regionSize; - items[2].top = o.header.length * o.headerRowSize; + items[2].top = this._getFreezeHeaderHeight(); items[3].left = regionSize; - items[3].top = o.header.length * o.headerRowSize; + items[3].top = this._getFreezeHeaderHeight(); this.contextLayout.attr("items", items); this.contextLayout.resize(); diff --git a/bi/core.js b/bi/core.js index 100e50c68..87cdaf46e 100644 --- a/bi/core.js +++ b/bi/core.js @@ -4521,7 +4521,7 @@ BI.Widget = BI.inherit(BI.OB, { } //递归将所有子组件使能 BI.each(this._children, function (i, child) { - child._setEnable && child._setEnable(enable); + !child._manualSetEnable && child._setEnable && child._setEnable(enable); }); }, @@ -4533,7 +4533,7 @@ BI.Widget = BI.inherit(BI.OB, { } //递归将所有子组件使有效 BI.each(this._children, function (i, child) { - child._setValid && child._setValid(valid); + !child._manualSetValid && child._setValid && child._setValid(valid); }); }, @@ -4546,6 +4546,7 @@ BI.Widget = BI.inherit(BI.OB, { }, setEnable: function (enable) { + this._manualSetEnable = true; this._setEnable(enable); if (enable === true) { this.element.removeClass("base-disabled disabled"); @@ -4567,7 +4568,7 @@ BI.Widget = BI.inherit(BI.OB, { }, setValid: function (valid) { - this.options.invalid = !valid; + this._manualSetValid = true; this._setValid(valid); if (valid === true) { this.element.removeClass("base-invalid invalid"); diff --git a/docs/base.js b/docs/base.js index 6df42bb8b..9aa2a6024 100644 --- a/docs/base.js +++ b/docs/base.js @@ -29054,11 +29054,26 @@ BI.CollectionTable = BI.inherit(BI.Widget, { return this.options.isNeedFreeze ? this.options.freezeCols.length : 0; }, + _getFreezeHeaderHeight: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return 0; + } + return o.header.length * o.headerRowSize; + }, + + _getActualItems: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return o.header.concat(o.items); + } + return o.items; + }, + _populateScrollbar: function () { var o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; - var freezeColLength = this._getFreezeColLength(); + summaryColumnSizeArray = []; BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { totalLeftColumnSize += size; @@ -29072,8 +29087,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; } }); - this.topScrollbar.setContentSize(o.items.length * o.rowSize); - this.topScrollbar.setSize(this._height - o.header.length * o.headerRowSize); + this.topScrollbar.setContentSize(this._getActualItems().length * o.rowSize); + this.topScrollbar.setSize(this._height - this._getFreezeHeaderHeight()); this.topScrollbar.setPosition(this.bottomRightCollection.getScrollTop()); this.topScrollbar.populate(); @@ -29088,7 +29103,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { this.rightScrollbar.populate(); var items = this.scrollBarLayout.attr("items"); - items[0].top = o.header.length * o.headerRowSize; + items[0].top = this._getFreezeHeaderHeight(); items[1].top = this._height; items[2].top = this._height; items[2].left = regionSize; @@ -29099,8 +29114,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _populateTable: function () { var self = this, o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; - var freezeColLength = this._getFreezeColLength(); + summaryColumnSizeArray = []; BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { totalLeftColumnSize += size; @@ -29116,13 +29130,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, { }); var otlw = regionSize; - var otlh = o.header.length * o.headerRowSize; + var otlh = this._getFreezeHeaderHeight(); var otrw = this._width - regionSize; - var otrh = o.header.length * o.headerRowSize; + var otrh = this._getFreezeHeaderHeight(); var oblw = regionSize; - var oblh = this._height - o.header.length * o.headerRowSize; + var oblh = this._height - otlh; var obrw = this._width - regionSize; - var obrh = this._height - o.header.length * o.headerRowSize; + var obrh = this._height - otrh; var tlw = otlw + this._scrollBarSize; var tlh = otlh + this._scrollBarSize; @@ -29166,9 +29180,9 @@ BI.CollectionTable = BI.inherit(BI.Widget, { var items = this.contextLayout.attr("items"); items[1].left = regionSize; - items[2].top = o.header.length * o.headerRowSize; + items[2].top = this._getFreezeHeaderHeight(); items[3].left = regionSize; - items[3].top = o.header.length * o.headerRowSize; + items[3].top = this._getFreezeHeaderHeight(); this.contextLayout.attr("items", items); this.contextLayout.resize(); @@ -29184,8 +29198,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { }; run(this.topLeftItems, o.header, leftHeader); run(this.topRightItems, o.header, rightHeader); - run(this.bottomLeftItems, o.items, leftItems); - run(this.bottomRightItems, o.items, rightItems); + run(this.bottomLeftItems, this._getActualItems(), leftItems); + run(this.bottomRightItems, this._getActualItems(), rightItems); this.topLeftCollection._populate(leftHeader); this.topRightCollection._populate(rightHeader); @@ -29196,13 +29210,23 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _digest: function () { var o = this.options; var freezeColLength = this._getFreezeColLength(); - this.topLeftItems = this._serialize(o.header, 0, freezeColLength, o.headerRowSize, o.columnSize, o.mergeCols); - this.topRightItems = this._serialize(o.header, freezeColLength, o.columnSize.length, o.headerRowSize, o.columnSize, true); - this.bottomLeftItems = this._serialize(o.items, 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols); - this.bottomRightItems = this._serialize(o.items, freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols); + //如果表头位置不够,取消表头冻结 + if (this._getFreezeHeaderHeight() <= 0) { + this.topLeftItems = []; + this.topRightItems = []; + this.bottomLeftItems = this._serialize(this._getActualItems(), 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols, BI.range(o.header.length)); + this.bottomRightItems = this._serialize(this._getActualItems(), freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols, BI.range(o.header.length)); + } else { + this.topLeftItems = this._serialize(o.header, 0, freezeColLength, o.headerRowSize, o.columnSize, o.mergeCols); + this.topRightItems = this._serialize(o.header, freezeColLength, o.columnSize.length, o.headerRowSize, o.columnSize, true); + this.bottomLeftItems = this._serialize(o.items, 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols); + this.bottomRightItems = this._serialize(o.items, freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols); + } }, - _serialize: function (items, startCol, endCol, rowHeight, columnSize, mergeCols) { + _serialize: function (items, startCol, endCol, rowHeight, columnSize, mergeCols, mergeRows) { + mergeCols = mergeCols || []; + mergeRows = mergeRows || []; var self = this, o = this.options; var result = [], cache = {}, preCol = {}, preRow = {}, map = {}; var summaryColumnSize = []; @@ -29252,7 +29276,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { } cache[i][j] = cols[j]; map[i][j] = {}; - if (mergeCols === true || mergeCols.indexOf(j) > -1) { + if (mergeCols === true || mergeCols.indexOf(j) > -1 || mergeRows === true || mergeRows.indexOf(i) > -1) { if (i === 0 && j === startCol) { createOneEl(0, startCol); } else if (j === startCol && i > 0) { @@ -29838,11 +29862,26 @@ BI.GridTable = BI.inherit(BI.Widget, { return this.options.isNeedFreeze ? this.options.freezeCols.length : 0; }, + _getFreezeHeaderHeight: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return 0; + } + return o.header.length * o.headerRowSize; + }, + + _getActualItems: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return o.header.concat(o.items); + } + return o.items; + }, + _populateScrollbar: function () { var o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; - var freezeColLength = this._getFreezeColLength(); + summaryColumnSizeArray = []; BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { totalLeftColumnSize += size; @@ -29856,8 +29895,8 @@ BI.GridTable = BI.inherit(BI.Widget, { summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; } }); - this.topScrollbar.setContentSize(o.items.length * o.rowSize); - this.topScrollbar.setSize(this._height - o.header.length * o.headerRowSize); + this.topScrollbar.setContentSize(this._getActualItems().length * o.rowSize); + this.topScrollbar.setSize(this._height - this._getFreezeHeaderHeight()); this.topScrollbar.setPosition(Math.min(this.bottomLeftGrid.getScrollTop(), this.bottomRightGrid.getScrollTop())); this.topScrollbar.populate(); @@ -29872,7 +29911,7 @@ BI.GridTable = BI.inherit(BI.Widget, { this.rightScrollbar.populate(); var items = this.scrollBarLayout.attr("items"); - items[0].top = o.header.length * o.headerRowSize; + items[0].top = this._getFreezeHeaderHeight(); items[1].top = this._height; items[2].top = this._height; items[2].left = regionSize; @@ -29906,7 +29945,7 @@ BI.GridTable = BI.inherit(BI.Widget, { var o = this.options; var freezeColLength = this._getFreezeColLength(); var leftItems = [], rightItems = []; - BI.each(o.items, function (i, cols) { + BI.each(this._getActualItems(), function (i, cols) { leftItems[i] = []; rightItems[i] = []; BI.each(cols, function (j, col) { @@ -29927,7 +29966,7 @@ BI.GridTable = BI.inherit(BI.Widget, { _populateTable: function () { var self = this, o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; + summaryColumnSizeArray = []; var freezeColLength = this._getFreezeColLength(); BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { @@ -29944,13 +29983,13 @@ BI.GridTable = BI.inherit(BI.Widget, { }); var otlw = regionSize; - var otlh = o.header.length * o.headerRowSize; + var otlh = this._getFreezeHeaderHeight(); var otrw = this._width - regionSize; - var otrh = o.header.length * o.headerRowSize; + var otrh = this._getFreezeHeaderHeight(); var oblw = regionSize; - var oblh = this._height - o.header.length * o.headerRowSize; + var oblh = this._height - otlh; var obrw = this._width - regionSize; - var obrh = this._height - o.header.length * o.headerRowSize; + var obrh = this._height - otrh; var tlw = otlw + this._scrollBarSize; var tlh = otlh + this._scrollBarSize; @@ -30003,9 +30042,9 @@ BI.GridTable = BI.inherit(BI.Widget, { var items = this.contextLayout.attr("items"); items[1].left = regionSize; - items[2].top = o.header.length * o.headerRowSize; + items[2].top = this._getFreezeHeaderHeight(); items[3].left = regionSize; - items[3].top = o.header.length * o.headerRowSize; + items[3].top = this._getFreezeHeaderHeight(); this.contextLayout.attr("items", items); this.contextLayout.resize(); diff --git a/docs/core.js b/docs/core.js index 5103bb804..b89a7f08d 100644 --- a/docs/core.js +++ b/docs/core.js @@ -14523,7 +14523,7 @@ BI.Widget = BI.inherit(BI.OB, { } //递归将所有子组件使能 BI.each(this._children, function (i, child) { - child._setEnable && child._setEnable(enable); + !child._manualSetEnable && child._setEnable && child._setEnable(enable); }); }, @@ -14535,7 +14535,7 @@ BI.Widget = BI.inherit(BI.OB, { } //递归将所有子组件使有效 BI.each(this._children, function (i, child) { - child._setValid && child._setValid(valid); + !child._manualSetValid && child._setValid && child._setValid(valid); }); }, @@ -14548,6 +14548,7 @@ BI.Widget = BI.inherit(BI.OB, { }, setEnable: function (enable) { + this._manualSetEnable = true; this._setEnable(enable); if (enable === true) { this.element.removeClass("base-disabled disabled"); @@ -14569,7 +14570,7 @@ BI.Widget = BI.inherit(BI.OB, { }, setValid: function (valid) { - this.options.invalid = !valid; + this._manualSetValid = true; this._setValid(valid); if (valid === true) { this.element.removeClass("base-invalid invalid"); diff --git a/src/base/table/table.collection.js b/src/base/table/table.collection.js index 63da1b991..ee5aea9aa 100644 --- a/src/base/table/table.collection.js +++ b/src/base/table/table.collection.js @@ -173,11 +173,26 @@ BI.CollectionTable = BI.inherit(BI.Widget, { return this.options.isNeedFreeze ? this.options.freezeCols.length : 0; }, + _getFreezeHeaderHeight: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return 0; + } + return o.header.length * o.headerRowSize; + }, + + _getActualItems: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return o.header.concat(o.items); + } + return o.items; + }, + _populateScrollbar: function () { var o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; - var freezeColLength = this._getFreezeColLength(); + summaryColumnSizeArray = []; BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { totalLeftColumnSize += size; @@ -191,8 +206,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; } }); - this.topScrollbar.setContentSize(o.items.length * o.rowSize); - this.topScrollbar.setSize(this._height - o.header.length * o.headerRowSize); + this.topScrollbar.setContentSize(this._getActualItems().length * o.rowSize); + this.topScrollbar.setSize(this._height - this._getFreezeHeaderHeight()); this.topScrollbar.setPosition(this.bottomRightCollection.getScrollTop()); this.topScrollbar.populate(); @@ -207,7 +222,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { this.rightScrollbar.populate(); var items = this.scrollBarLayout.attr("items"); - items[0].top = o.header.length * o.headerRowSize; + items[0].top = this._getFreezeHeaderHeight(); items[1].top = this._height; items[2].top = this._height; items[2].left = regionSize; @@ -218,8 +233,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _populateTable: function () { var self = this, o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; - var freezeColLength = this._getFreezeColLength(); + summaryColumnSizeArray = []; BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { totalLeftColumnSize += size; @@ -235,13 +249,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, { }); var otlw = regionSize; - var otlh = o.header.length * o.headerRowSize; + var otlh = this._getFreezeHeaderHeight(); var otrw = this._width - regionSize; - var otrh = o.header.length * o.headerRowSize; + var otrh = this._getFreezeHeaderHeight(); var oblw = regionSize; - var oblh = this._height - o.header.length * o.headerRowSize; + var oblh = this._height - otlh; var obrw = this._width - regionSize; - var obrh = this._height - o.header.length * o.headerRowSize; + var obrh = this._height - otrh; var tlw = otlw + this._scrollBarSize; var tlh = otlh + this._scrollBarSize; @@ -285,9 +299,9 @@ BI.CollectionTable = BI.inherit(BI.Widget, { var items = this.contextLayout.attr("items"); items[1].left = regionSize; - items[2].top = o.header.length * o.headerRowSize; + items[2].top = this._getFreezeHeaderHeight(); items[3].left = regionSize; - items[3].top = o.header.length * o.headerRowSize; + items[3].top = this._getFreezeHeaderHeight(); this.contextLayout.attr("items", items); this.contextLayout.resize(); @@ -303,8 +317,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, { }; run(this.topLeftItems, o.header, leftHeader); run(this.topRightItems, o.header, rightHeader); - run(this.bottomLeftItems, o.items, leftItems); - run(this.bottomRightItems, o.items, rightItems); + run(this.bottomLeftItems, this._getActualItems(), leftItems); + run(this.bottomRightItems, this._getActualItems(), rightItems); this.topLeftCollection._populate(leftHeader); this.topRightCollection._populate(rightHeader); @@ -315,13 +329,23 @@ BI.CollectionTable = BI.inherit(BI.Widget, { _digest: function () { var o = this.options; var freezeColLength = this._getFreezeColLength(); - this.topLeftItems = this._serialize(o.header, 0, freezeColLength, o.headerRowSize, o.columnSize, o.mergeCols); - this.topRightItems = this._serialize(o.header, freezeColLength, o.columnSize.length, o.headerRowSize, o.columnSize, true); - this.bottomLeftItems = this._serialize(o.items, 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols); - this.bottomRightItems = this._serialize(o.items, freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols); + //如果表头位置不够,取消表头冻结 + if (this._getFreezeHeaderHeight() <= 0) { + this.topLeftItems = []; + this.topRightItems = []; + this.bottomLeftItems = this._serialize(this._getActualItems(), 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols, BI.range(o.header.length)); + this.bottomRightItems = this._serialize(this._getActualItems(), freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols, BI.range(o.header.length)); + } else { + this.topLeftItems = this._serialize(o.header, 0, freezeColLength, o.headerRowSize, o.columnSize, o.mergeCols); + this.topRightItems = this._serialize(o.header, freezeColLength, o.columnSize.length, o.headerRowSize, o.columnSize, true); + this.bottomLeftItems = this._serialize(o.items, 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols); + this.bottomRightItems = this._serialize(o.items, freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols); + } }, - _serialize: function (items, startCol, endCol, rowHeight, columnSize, mergeCols) { + _serialize: function (items, startCol, endCol, rowHeight, columnSize, mergeCols, mergeRows) { + mergeCols = mergeCols || []; + mergeRows = mergeRows || []; var self = this, o = this.options; var result = [], cache = {}, preCol = {}, preRow = {}, map = {}; var summaryColumnSize = []; @@ -371,7 +395,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, { } cache[i][j] = cols[j]; map[i][j] = {}; - if (mergeCols === true || mergeCols.indexOf(j) > -1) { + if (mergeCols === true || mergeCols.indexOf(j) > -1 || mergeRows === true || mergeRows.indexOf(i) > -1) { if (i === 0 && j === startCol) { createOneEl(0, startCol); } else if (j === startCol && i > 0) { diff --git a/src/base/table/table.grid.js b/src/base/table/table.grid.js index 155b5b614..1eae8487b 100644 --- a/src/base/table/table.grid.js +++ b/src/base/table/table.grid.js @@ -176,11 +176,26 @@ BI.GridTable = BI.inherit(BI.Widget, { return this.options.isNeedFreeze ? this.options.freezeCols.length : 0; }, + _getFreezeHeaderHeight: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return 0; + } + return o.header.length * o.headerRowSize; + }, + + _getActualItems: function () { + var o = this.options; + if (o.header.length * o.headerRowSize >= this._height) { + return o.header.concat(o.items); + } + return o.items; + }, + _populateScrollbar: function () { var o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; - var freezeColLength = this._getFreezeColLength(); + summaryColumnSizeArray = []; BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { totalLeftColumnSize += size; @@ -194,8 +209,8 @@ BI.GridTable = BI.inherit(BI.Widget, { summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; } }); - this.topScrollbar.setContentSize(o.items.length * o.rowSize); - this.topScrollbar.setSize(this._height - o.header.length * o.headerRowSize); + this.topScrollbar.setContentSize(this._getActualItems().length * o.rowSize); + this.topScrollbar.setSize(this._height - this._getFreezeHeaderHeight()); this.topScrollbar.setPosition(Math.min(this.bottomLeftGrid.getScrollTop(), this.bottomRightGrid.getScrollTop())); this.topScrollbar.populate(); @@ -210,7 +225,7 @@ BI.GridTable = BI.inherit(BI.Widget, { this.rightScrollbar.populate(); var items = this.scrollBarLayout.attr("items"); - items[0].top = o.header.length * o.headerRowSize; + items[0].top = this._getFreezeHeaderHeight(); items[1].top = this._height; items[2].top = this._height; items[2].left = regionSize; @@ -244,7 +259,7 @@ BI.GridTable = BI.inherit(BI.Widget, { var o = this.options; var freezeColLength = this._getFreezeColLength(); var leftItems = [], rightItems = []; - BI.each(o.items, function (i, cols) { + BI.each(this._getActualItems(), function (i, cols) { leftItems[i] = []; rightItems[i] = []; BI.each(cols, function (j, col) { @@ -265,7 +280,7 @@ BI.GridTable = BI.inherit(BI.Widget, { _populateTable: function () { var self = this, o = this.options; var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, - summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; + summaryColumnSizeArray = []; var freezeColLength = this._getFreezeColLength(); BI.each(o.columnSize, function (i, size) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { @@ -282,13 +297,13 @@ BI.GridTable = BI.inherit(BI.Widget, { }); var otlw = regionSize; - var otlh = o.header.length * o.headerRowSize; + var otlh = this._getFreezeHeaderHeight(); var otrw = this._width - regionSize; - var otrh = o.header.length * o.headerRowSize; + var otrh = this._getFreezeHeaderHeight(); var oblw = regionSize; - var oblh = this._height - o.header.length * o.headerRowSize; + var oblh = this._height - otlh; var obrw = this._width - regionSize; - var obrh = this._height - o.header.length * o.headerRowSize; + var obrh = this._height - otrh; var tlw = otlw + this._scrollBarSize; var tlh = otlh + this._scrollBarSize; @@ -341,9 +356,9 @@ BI.GridTable = BI.inherit(BI.Widget, { var items = this.contextLayout.attr("items"); items[1].left = regionSize; - items[2].top = o.header.length * o.headerRowSize; + items[2].top = this._getFreezeHeaderHeight(); items[3].left = regionSize; - items[3].top = o.header.length * o.headerRowSize; + items[3].top = this._getFreezeHeaderHeight(); this.contextLayout.attr("items", items); this.contextLayout.resize(); diff --git a/src/core/widget.js b/src/core/widget.js index a868b4d31..610b38492 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -198,7 +198,7 @@ BI.Widget = BI.inherit(BI.OB, { } //递归将所有子组件使能 BI.each(this._children, function (i, child) { - child._setEnable && child._setEnable(enable); + !child._manualSetEnable && child._setEnable && child._setEnable(enable); }); }, @@ -210,7 +210,7 @@ BI.Widget = BI.inherit(BI.OB, { } //递归将所有子组件使有效 BI.each(this._children, function (i, child) { - child._setValid && child._setValid(valid); + !child._manualSetValid && child._setValid && child._setValid(valid); }); }, @@ -223,6 +223,7 @@ BI.Widget = BI.inherit(BI.OB, { }, setEnable: function (enable) { + this._manualSetEnable = true; this._setEnable(enable); if (enable === true) { this.element.removeClass("base-disabled disabled"); @@ -244,7 +245,7 @@ BI.Widget = BI.inherit(BI.OB, { }, setValid: function (valid) { - this.options.invalid = !valid; + this._manualSetValid = true; this._setValid(valid); if (valid === true) { this.element.removeClass("base-invalid invalid");