Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid: Fix column resizing when columnResizingMode is widget and rtlEnabled is true (T837344) #13060

Merged
merged 4 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions js/ui/grid_core/ui.grid_core.columns_resizing_reordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,17 @@ const ColumnsResizerViewController = modules.ViewController.inherit({
return false;
},

_isRtlParentStyle: function() {
return this.option('rtlEnabled') && this._$parentContainer?.parent().css('direction') === 'rtl';
},

_pointCreated: function(point, cellsLength, columns) {
const isNextColumnMode = isNextColumnResizingMode(this);
const rtlEnabled = this.option('rtlEnabled');
const firstPointColumnIndex = !isNextColumnMode && rtlEnabled ? 0 : 1;
const isRtlParentStyle = this._isRtlParentStyle();
const firstPointColumnIndex = !isNextColumnMode && rtlEnabled && !isRtlParentStyle ? 0 : 1;

if(point.index >= firstPointColumnIndex && point.index < cellsLength + (!isNextColumnMode && !rtlEnabled ? 1 : 0)) {
if(point.index >= firstPointColumnIndex && point.index < cellsLength + (!isNextColumnMode && (!rtlEnabled || isRtlParentStyle) ? 1 : 0)) {
point.columnIndex -= firstPointColumnIndex;
const currentColumn = columns[point.columnIndex] || {};
const nextColumn = columns[point.columnIndex + 1] || {};
Expand Down Expand Up @@ -613,12 +618,14 @@ const ColumnsResizerViewController = modules.ViewController.inherit({
const parentOffset = that._$parentContainer.offset();
const parentOffsetLeft = parentOffset.left;
const eventData = getEventData(e);
const rtlEnabled = that.option('rtlEnabled');
const isRtlParentStyle = this._isRtlParentStyle();

if(that._isResizing && that._resizingInfo) {
if(parentOffsetLeft <= eventData.x && (!isNextColumnMode || eventData.x <= parentOffsetLeft + that._$parentContainer.width())) {
if((parentOffsetLeft <= eventData.x || !isNextColumnMode && isRtlParentStyle) && (!isNextColumnMode || eventData.x <= parentOffsetLeft + that._$parentContainer.width())) {
if(that._updateColumnsWidthIfNeeded(eventData.x)) {
const $cell = that._columnHeadersView.getColumnElements().eq(that._resizingInfo.currentColumnIndex);
that._columnsSeparatorView.moveByX($cell.offset().left + (isNextColumnMode && that.option('rtlEnabled') ? 0 : $cell.outerWidth()));
that._columnsSeparatorView.moveByX($cell.offset().left + ((isNextColumnMode || isRtlParentStyle) && rtlEnabled ? 0 : $cell.outerWidth()));
that._tablePositionController.update(that._targetPoint.y);
e.preventDefault();
}
Expand Down Expand Up @@ -724,6 +731,12 @@ const ColumnsResizerViewController = modules.ViewController.inherit({
that._tablePositionController.update(that._targetPoint.y);
that._columnsSeparatorView.show();
that._trackerView.show();
const scrollable = that.component.getScrollable();

if(scrollable && that._isRtlParentStyle()) {
that._scrollRight = scrollable.$content().width() - scrollable._container().width() - scrollable.scrollLeft();
}

e.preventDefault();
e.stopPropagation();
}
Expand Down Expand Up @@ -782,6 +795,8 @@ const ColumnsResizerViewController = modules.ViewController.inherit({
let minWidth;
let nextColumn;
let cellWidth;
const rtlEnabled = this.option('rtlEnabled');
const isRtlParentStyle = this._isRtlParentStyle();

function isPercentWidth(width) {
return typeUtils.isString(width) && width.slice(-1) === '%';
Expand Down Expand Up @@ -824,7 +839,7 @@ const ColumnsResizerViewController = modules.ViewController.inherit({
}

deltaX = posX - resizingInfo.startPosX;
if(isNextColumnMode && this.option('rtlEnabled')) {
if((isNextColumnMode || isRtlParentStyle) && rtlEnabled) {
deltaX = -deltaX;
}
cellWidth = resizingInfo.currentColumnWidth + deltaX;
Expand Down Expand Up @@ -871,6 +886,12 @@ const ColumnsResizerViewController = modules.ViewController.inherit({
columnsController.endUpdate();
if(!isNextColumnMode) {
this.component.updateDimensions();

const scrollable = this.component.getScrollable();
if(scrollable && isRtlParentStyle) {
const left = scrollable.$content().width() - scrollable._container().width() - this._scrollRight;
scrollable.scrollTo({ left: left });
}
}
}

Expand Down Expand Up @@ -920,7 +941,7 @@ const ColumnsResizerViewController = modules.ViewController.inherit({
that._rowsView = that.getView('rowsView');
that._columnsController = that.getController('columns');
that._tablePositionController = that.getController('tablePosition');
that._$parentContainer = that._columnsSeparatorView.component.$element();
that._$parentContainer = that.component.$element();

that._subscribeToCallback(that._columnHeadersView.renderCompleted, generatePointsByColumnsHandler);
that._subscribeToCallback(that._columnHeadersView.resizeCompleted, generatePointsByColumnsHandler);
Expand Down
Loading