Skip to content

Instantly share code, notes, and snippets.

@btoll
Created June 20, 2013 17:46
Show Gist options
  • Save btoll/5824931 to your computer and use it in GitHub Desktop.
Save btoll/5824931 to your computer and use it in GitHub Desktop.
Vertafore patch for EXTJSIV-10055
Ext.define('EXTJSIV-10055.grid.ColumnLayout', {
override: 'Ext.grid.ColumnLayout',
calculate: function(ownerContext) {
this.callSuper(arguments);
// If we have calculated the widths, then if forceFit, and there are no flexes, we cannot tell the
// TableLayout we are done. We will have to go through the convertWidthsToFlexes stage.
if (ownerContext.state.parallelDone) {
// TODO: auto width columns aren't necessarily done here.
// see view.TableLayout, there is a work around for that there
ownerContext.setProp('columnWidthsDone', true);
}
// Collect the height of the data table if we need it to determine overflow
if (ownerContext.viewContext) {
ownerContext.state.tableHeight = ownerContext.viewTable.offsetHeight;
}
}
});
Ext.define('EXTJSIV_10055.grid.column.Column', {
override: 'Ext.grid.column.Column',
show: function(fromOwner, fromChild) {
var me = this,
ownerHeaderCt = me.getOwnerHeaderCt(),
ownerCt = me.ownerCt,
items,
len, i,
item;
if (me.isVisible()) {
return me;
}
if (!me.rendered) {
me.hidden = false;
return;
}
// Size all other columns to accommodate re-shown column
if (ownerHeaderCt.forceFit) {
ownerHeaderCt.applyForceFit(me);
}
Ext.suspendLayouts();
// If a sub header, ensure that the group header is visible
if (me.isSubHeader && ownerCt.hidden) {
ownerCt.show(false, true);
}
me.callSuper(arguments);
// If we've just shown a group with all its sub headers hidden, then show all its sub headers
if (me.isGroupHeader && fromChild !== true && !me.query(':not([hidden])').length) {
items = me.items.items;
for (i = 0, len = items.length; i < len; i++) {
item = items[i];
if (item.hidden) {
item.show(true);
}
}
}
Ext.resumeLayouts(true);
// Notify owning HeaderContainer AFTER layout has been flushed so that header and headerCt widths are all correct
ownerCt = me.getOwnerHeaderCt();
if (ownerCt) {
ownerCt.onHeaderShow(me);
}
}
});
Ext.define('EXTJSIV-10055.grid.header.Container', {
override: 'Ext.grid.header.Container',
applyForceFit: function (header) {
var me = this,
view = me.view,
minWidth = Ext.grid.plugin.HeaderResizer.prototype.minColWidth,
// Used when a column's max contents are larger than the available view width.
useMinWidthForFlex = false,
defaultWidth = Ext.grid.header.Container.prototype.defaultWidth,
availFlex = me.el.getViewSize().width - (view.el.dom.scrollHeight > view.el.dom.clientHeight ? Ext.getScrollbarSize().width : 0),
totalFlex = 0,
availFlex,
items = me.getVisibleGridColumns(),
hidden = header.hidden,
len, i,
item,
maxAvailFlexOneColumn,
myWidth;
function getTotalFlex() {
for (i = 0, len = items.length; i < len; i++) {
item = items[i];
// Skip the current header.
if (item === header) {
continue;
}
item.flex = item.flex || item.width || item.getWidth();
totalFlex += item.flex;
item.width = null;
}
}
function applyWidth() {
// The currently-sized column (whether resized or reshown) will already
// have a width, so all other columns will need to be flexed.
for (i = 0, len = items.length; i < len; i++) {
item = items[i],
isCurrentHeader = (item === header);
if (useMinWidthForFlex && !isCurrentHeader) {
// The selected column is extremely large so set all the others as flex minWidth.
item.flex = minWidth;
item.width = null;
} else if (!isCurrentHeader) {
// Note that any widths MUST be converted to flex. Imagine that all but one columns
// are hidden. The widths of each column very easily could be greater than the total
// available width (think about the how visible header widths increase as sibling
// columns are hidden), so they cannot be reliably used to size the header, and the only
// safe approach is to convert any all widths to flex (except for the current header).
myWidth = item.flex || defaultWidth;
item.flex = Math.max(Math.ceil((myWidth / totalFlex) * availFlex), minWidth);
item.width = null;
}
item.setWidth(item.width || item.flex);
}
}
Ext.suspendLayouts();
// Determine the max amount of flex that a single column can have.
maxAvailFlexOneColumn = (availFlex - ((items.length + 1) * minWidth));
// First, remove the header's flex as it should always receive a set width
// since it is the header being operated on.
header.flex = null;
if (hidden) {
// Push the hidden (soon to be shown) header onto the stack so it can be operated on.
items.push(header);
myWidth = header.width || header.savedWidth;
header.savedWidth = null;
} else {
myWidth = view.getMaxContentWidth(header);
}
// We need to know if the max content width of the selected column would blow out the
// grid. If so, all the other visible columns will be flexed to minWidth.
if (myWidth > maxAvailFlexOneColumn) {
header.width = maxAvailFlexOneColumn;
useMinWidthForFlex = true;
} else {
header.width = myWidth;
// Substract the current header's width from the available flex + some padding
// to ensure that the last column doesn't get nudged out of the view.
availFlex -= myWidth + defaultWidth;
getTotalFlex();
}
applyWidth();
Ext.resumeLayouts(true);
},
autoSizeColumn: function (header) {
var view = this.view;
if (view) {
view.autoSizeColumn(header);
if (this.forceFit) {
this.applyForceFit(header);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment