devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
884 lines (882 loc) • 38.8 kB
JavaScript
/**
* DevExtreme (cjs/__internal/grids/grid_core/focus/m_focus.js)
* Version: 26.1.6
* Build date: Fri Oct 16 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.rowsView = exports.keyboardNavigation = exports.focusEditorFactoryViewControllerExtender = exports.focusDataControllerExtender = exports.editing = exports.columns = exports.FocusController = void 0;
var _renderer = _interopRequireDefault(require("../../../../core/renderer"));
var _common = require("../../../../core/utils/common");
var _deferred = require("../../../../core/utils/deferred");
var _iterator = require("../../../../core/utils/iterator");
var _type = require("../../../../core/utils/type");
var _const = require("../../../grids/grid_core/views/const");
var _m_editing_utils = require("../editing/m_editing_utils");
var _utils = require("../filter/utils");
var _m_utils = _interopRequireDefault(require("../m_utils"));
var _modules = _interopRequireDefault(require("../modules/modules"));
var _focus_utils = require("./focus_utils");
function _interopRequireDefault(e) {
return e && e.__esModule ? e : {
default: e
}
}
const ROW_FOCUSED_CLASS = "dx-row-focused";
const FOCUSED_ROW_SELECTOR = `.${_const.CLASSES.row}.dx-row-focused`;
const CELL_FOCUS_DISABLED_CLASS = "dx-cell-focus-disabled";
class FocusController extends _modules.default.ViewController {
constructor() {
super(...arguments);
this.handleDataChanged = e => {
var _e$items;
const dataController = this.getDataController();
const dataSourceController = this.getDataSourceController();
const forceUpdateFocusedRow = dataSourceController.consumeDataPushed();
if (!this.option("focusedRowEnabled") || !dataSourceController.hasAdapter()) {
return
}
const isPartialUpdate = "update" === e.changeType && e.repaintChangesOnly;
const isPartialUpdateWithDeleting = isPartialUpdate && !!e.changeTypes && e.changeTypes.includes("remove");
const isRefreshWithItems = "refresh" === e.changeType && !!(null !== (_e$items = e.items) && void 0 !== _e$items && _e$items.length);
const isAppendOrPrepend = "append" === e.changeType || "prepend" === e.changeType;
if (forceUpdateFocusedRow && dataController.isEmpty()) {
this._resetFocusedRow()
} else if (isRefreshWithItems || isPartialUpdateWithDeleting) {
dataController._updatePageIndexes();
this.updateFocusedRowIfNeeded(e, forceUpdateFocusedRow)
} else if (isAppendOrPrepend) {
dataController._updatePageIndexes()
} else if (isPartialUpdate) {
this.updateFocusedRowIfNeeded(e, forceUpdateFocusedRow);
this.resetStaleFocusedRowAfterPartialUpdate(e)
}
}
}
getKeyboardController() {
return this.getController("keyboardNavigation")
}
getDataController() {
return this.getController("data")
}
getDataSourceController() {
return this.getController("dataSource")
}
init() {
this.component._optionsByReference.focusedRowKey = true;
const dataController = this.getDataController();
dataController.afterChanged.remove(this.handleDataChanged);
dataController.afterChanged.add(this.handleDataChanged);
const lastChange = dataController.getLastChange();
if (lastChange) {
this.handleDataChanged(lastChange)
}
}
resetStaleFocusedRowAfterPartialUpdate(e) {
var _e$rowIndices;
const focusedRowKey = this.option("focusedRowKey");
if (!(0, _type.isDefined)(focusedRowKey)) {
return
}
const focusedRowIndex = this.getDataController().getRowIndexByKey(focusedRowKey);
const isFocusedRowVisible = focusedRowIndex >= 0;
const isFocusedRowInChange = !!(null !== (_e$rowIndices = e.rowIndices) && void 0 !== _e$rowIndices && _e$rowIndices.includes(focusedRowIndex));
if (isFocusedRowVisible && isFocusedRowInChange) {
this.updateFocusedRow({
focusedRowKey: focusedRowKey,
preventScroll: true
})
}
}
updateFocusedRowIfNeeded(e) {
let forceUpdate = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : false;
const operationTypes = e.operationTypes || {};
const {
reload: reload,
fullReload: fullReload,
pageIndex: pageIndex,
paging: paging
} = operationTypes;
const isVirtualScrolling = this.getKeyboardController()._isVirtualScrolling();
const pagingWithoutVirtualScrolling = paging && !isVirtualScrolling;
const focusedRowKey = this.option("focusedRowKey");
const isAutoNavigate = this.isAutoNavigateToFocusedRow();
const isReload = reload && false === pageIndex;
const rowIndexByKey = this.getDataController().getRowIndexByKey(focusedRowKey);
switch (true) {
case forceUpdate:
this._focusRowByKeyOrIndex();
break;
case isReload && !fullReload && (0, _type.isDefined)(focusedRowKey):
this._navigateToRow(focusedRowKey, true).done(focusedRowIndex => {
if (focusedRowIndex < 0) {
this._focusRowByIndex(void 0, operationTypes)
}
});
break;
case pagingWithoutVirtualScrolling && isAutoNavigate: {
const focusedRowIndex = this.option("focusedRowIndex");
const isValidRowIndexByKey = rowIndexByKey >= 0;
const isValidFocusedRowIndex = focusedRowIndex >= 0;
const isSameRowIndex = focusedRowIndex === rowIndexByKey;
if (isValidFocusedRowIndex && (isSameRowIndex || !isValidRowIndexByKey)) {
this._focusRowByIndex(focusedRowIndex, operationTypes)
}
break
}
case pagingWithoutVirtualScrolling && !isAutoNavigate && rowIndexByKey < 0:
this.option("focusedRowIndex", -1);
break;
case operationTypes.fullReload:
this._focusRowByKeyOrIndex()
}
}
optionChanged(args) {
const {
name: name,
value: value,
previousValue: previousValue
} = args;
switch (name) {
case "focusedRowIndex":
this._focusRowByIndex(value);
this.getKeyboardController()._fireFocusedRowChanged();
args.handled = true;
break;
case "focusedRowKey":
if (Array.isArray(value) && JSON.stringify(value) === JSON.stringify(previousValue)) {
return
}
this._focusRowByKey(value).done(() => {
this.getKeyboardController()._fireFocusedRowChanged()
});
args.handled = true;
break;
case "focusedColumnIndex":
case "focusedRowEnabled":
case "autoNavigateToFocusedRow":
args.handled = true;
break;
default:
super.optionChanged(args)
}
}
publicMethods() {
return ["navigateToRow", "isRowFocused"]
}
isAutoNavigateToFocusedRow() {
return "infinite" !== this.option("scrolling.mode") && this.option("autoNavigateToFocusedRow")
}
_focusRowByIndex(index, operationTypes) {
if (!this.option("focusedRowEnabled")) {
return
}
const currentIndex = void 0 !== index ? index : this.option("focusedRowIndex");
if (currentIndex < 0) {
if (this.isAutoNavigateToFocusedRow()) {
this._resetFocusedRow()
}
} else {
this._focusRowByIndexCore(currentIndex, operationTypes)
}
}
_focusRowByIndexCore(index, operationTypes) {
const pageSize = this.getDataController().pageSize();
const setKeyByIndex = () => {
if (this._isValidFocusedRowIndex(index)) {
let rowIndex = index - this.getDataController().getRowIndexOffset(true);
if (!operationTypes || operationTypes.paging && !operationTypes.filtering) {
const lastItemIndex = this.getDataController()._getLastItemIndex();
rowIndex = Math.min(rowIndex, lastItemIndex)
}
const focusedRowKey = this.getDataController().getKeyByRowIndex(rowIndex, true);
if ((0, _type.isDefined)(focusedRowKey) && !this.isRowFocused(focusedRowKey)) {
this.option("focusedRowKey", focusedRowKey)
}
}
};
if (pageSize >= 0) {
if (!this._isLocalRowIndex(index)) {
const pageIndex = Math.floor(index / this.getDataController().pageSize());
(0, _deferred.when)(this.getDataController().pageIndex(pageIndex), this.getDataController().waitReady()).done(() => {
setKeyByIndex()
})
} else {
setKeyByIndex()
}
}
}
_isLocalRowIndex(index) {
const isVirtualScrolling = this.getKeyboardController()._isVirtualScrolling();
if (isVirtualScrolling) {
const pageIndex = Math.floor(index / this.getDataController().pageSize());
const virtualItems = this.getDataController().virtualItemsCount();
const virtualItemsBegin = virtualItems ? virtualItems.begin : -1;
const visibleRowsCount = this.getDataController().getVisibleRows().length + this.getDataController().getRowIndexOffset();
const visiblePagesCount = Math.ceil(visibleRowsCount / this.getDataController().pageSize());
return virtualItemsBegin <= index && visiblePagesCount > pageIndex
}
return true
}
_setFocusedRowKeyByIndex(index) {
if (this._isValidFocusedRowIndex(index)) {
const rowIndex = Math.min(index - this.getDataController().getRowIndexOffset(), this.getDataController().items().length - 1);
const focusedRowKey = this.getDataController().getKeyByRowIndex(rowIndex);
if ((0, _type.isDefined)(focusedRowKey) && !this.isRowFocused(focusedRowKey)) {
this.option("focusedRowKey", focusedRowKey)
}
}
}
_focusRowByKey(key) {
if (!(0, _type.isDefined)(key)) {
this._resetFocusedRow();
return (0, _deferred.Deferred)().resolve()
}
return this._navigateToRow(key, true)
}
_resetFocusedRow() {
const focusedRowKey = this.option("focusedRowKey");
const isFocusedRowKeyDefined = (0, _type.isDefined)(focusedRowKey);
if (!isFocusedRowKeyDefined && this.option("focusedRowIndex") < 0) {
return
}
if (isFocusedRowKeyDefined) {
this.option("focusedRowKey", null)
}
this.getKeyboardController().setFocusedRowIndex(-1);
this.option("focusedRowIndex", -1);
this.getDataController().updateItems({
changeType: "updateFocusedRow",
focusedRowKey: null
});
this.getKeyboardController()._fireFocusedRowChanged()
}
_isValidFocusedRowIndex(rowIndex) {
const row = this.getDataController().getVisibleRows()[rowIndex];
return !row || "data" === row.rowType || "group" === row.rowType
}
navigateToRow(key) {
if (!this.isAutoNavigateToFocusedRow()) {
this.option("focusedRowIndex", -1)
}
return this._navigateToRow(key, false)
}
_navigateToRow(key, needFocusRow) {
const that = this;
const isAutoNavigate = that.isAutoNavigateToFocusedRow();
const d = new _deferred.Deferred;
const rowsView = this.getView("rowsView");
if (void 0 === key || !this.getDataSourceController().hasAdapter()) {
return d.reject().promise()
}
const rowIndexByKey = that.getFocusedRowIndexByKey(key);
if (!isAutoNavigate && needFocusRow || rowIndexByKey >= 0) {
that._navigateTo(key, d, needFocusRow)
} else {
this.getDataController().getPageIndexByKey(key).done(pageIndex => {
if (pageIndex < 0) {
d.resolve(-1);
return
}
if (pageIndex === this.getDataController().pageIndex()) {
this.getDataController().reload().done(() => {
if (that.isRowFocused(key) && this.getDataController().getRowIndexByKey(key) >= 0) {
d.resolve(that.getFocusedRowIndexByKey(key))
} else {
that._navigateTo(key, d, needFocusRow)
}
}).fail(d.reject)
} else {
this.getDataController().pageIndex(pageIndex).done(() => {
rowsView.waitAsyncTemplates(true).done(() => {
that._navigateTo(key, d, needFocusRow)
})
}).fail(d.reject)
}
}).fail(d.reject)
}
return d.promise()
}
_navigateTo(key, deferred, needFocusRow) {
const visibleRowIndex = this.getDataController().getRowIndexByKey(key);
const isVirtualRowRenderingMode = _m_utils.default.isVirtualRowRendering(this);
const isAutoNavigate = this.isAutoNavigateToFocusedRow();
if (isAutoNavigate && isVirtualRowRenderingMode && visibleRowIndex < 0) {
this._navigateToVirtualRow(key, deferred, needFocusRow)
} else {
this._navigateToVisibleRow(key, deferred, needFocusRow)
}
}
_navigateToVisibleRow(key, deferred, needFocusRow) {
if (needFocusRow) {
this._triggerUpdateFocusedRow(key, deferred)
} else {
const focusedRowIndex = this.getFocusedRowIndexByKey(key);
this.getView("rowsView").scrollToRowElement(key, deferred).done(() => {
deferred.resolve(focusedRowIndex)
})
}
}
_navigateToVirtualRow(key, deferred, needFocusRow) {
const rowsScrollController = this.getDataController()._rowsScrollController;
const rowIndex = _m_utils.default.getIndexByKey(key, this.getDataController().items(true));
const scrollable = this.getView("rowsView").getScrollable();
if (rowsScrollController && scrollable && rowIndex >= 0) {
const focusedRowIndex = rowIndex + this.getDataController().getRowIndexOffset(true);
const offset = rowsScrollController.getItemOffset(focusedRowIndex);
const triggerUpdateFocusedRow = () => {
if (this.getDataSourceController().totalCount() && !this.getDataController().items().length) {
return
}
this.component.off("contentReady", triggerUpdateFocusedRow);
if (needFocusRow) {
this._triggerUpdateFocusedRow(key, deferred)
} else {
deferred.resolve(focusedRowIndex)
}
};
this.component.on("contentReady", triggerUpdateFocusedRow);
this.getView("rowsView").scrollTopPosition(offset)
} else {
deferred.resolve(-1)
}
}
_triggerUpdateFocusedRow(key, deferred) {
const focusedRowIndex = this.getFocusedRowIndexByKey(key);
if (this._isValidFocusedRowIndex(focusedRowIndex)) {
let d;
if (this.option("focusedRowEnabled")) {
this.getDataController().updateItems({
changeType: "updateFocusedRow",
focusedRowKey: key
})
} else {
d = this.getView("rowsView").scrollToRowElement(key)
}(0, _deferred.when)(d).done(() => {
this.getKeyboardController().setFocusedRowIndex(focusedRowIndex);
deferred && deferred.resolve(focusedRowIndex)
})
} else {
deferred && deferred.resolve(-1)
}
}
getFocusedRowIndexByKey(key) {
const loadedRowIndex = this.getDataController().getRowIndexByKey(key, true);
return loadedRowIndex >= 0 ? loadedRowIndex + this.getDataController().getRowIndexOffset(true) : -1
}
_focusRowByKeyOrIndex() {
const focusedRowKey = this.option("focusedRowKey");
let currentFocusedRowIndex = this.option("focusedRowIndex");
if ((0, _type.isDefined)(focusedRowKey)) {
const visibleRowIndex = this.getDataController().getRowIndexByKey(focusedRowKey);
if (visibleRowIndex >= 0) {
if (this.getKeyboardController()._isVirtualScrolling()) {
currentFocusedRowIndex = visibleRowIndex + this.getDataController().getRowIndexOffset()
}
this.getKeyboardController().setFocusedRowIndex(currentFocusedRowIndex);
this._triggerUpdateFocusedRow(focusedRowKey)
} else {
this._navigateToRow(focusedRowKey, true).done(focusedRowIndex => {
if (currentFocusedRowIndex >= 0 && focusedRowIndex < 0) {
this._focusRowByIndex()
} else if (currentFocusedRowIndex < 0 && focusedRowIndex >= 0) {
this.getKeyboardController().setFocusedRowIndex(focusedRowIndex)
}
})
}
} else if (currentFocusedRowIndex >= 0) {
this._focusRowByIndex(currentFocusedRowIndex)
}
}
isRowFocused(key) {
const focusedRowKey = this.option("focusedRowKey");
if ((0, _type.isDefined)(focusedRowKey)) {
return (0, _common.equalByValue)(key, this.option("focusedRowKey"))
}
return
}
updateFocusedRow(e) {
const that = this;
const focusedRowIndex = that.getDataController().getRowIndexByKey(e.focusedRowKey);
const rowsView = that.getView("rowsView");
let $tableElement;
let $mainRow;
(0, _iterator.each)(rowsView.getTableElements(), (index, element) => {
const isMainTable = 0 === index;
$tableElement = (0, _renderer.default)(element);
that._clearPreviousFocusedRow($tableElement, focusedRowIndex);
const $row = that._prepareFocusedRow({
changedItem: that.getDataController().getVisibleRows()[focusedRowIndex],
$tableElement: $tableElement,
focusedRowIndex: focusedRowIndex
});
if (isMainTable) {
$mainRow = $row
}
});
if (!e.preventScroll && $mainRow) {
rowsView.scrollToElementVertically($mainRow)
}
}
_clearPreviousFocusedRow($tableElement, focusedRowIndex) {
const $prevRowFocusedElement = $tableElement.find(FOCUSED_ROW_SELECTOR).filter((_, focusedRow) => {
const $focusedRowTable = (0, _renderer.default)(focusedRow).closest(`.${this.addWidgetPrefix(_const.CLASSES.table)}`);
return $tableElement.is($focusedRowTable)
});
$prevRowFocusedElement.removeClass("dx-row-focused").removeClass("dx-cell-focus-disabled").removeAttr("tabindex");
$prevRowFocusedElement.children("td").removeAttr("tabindex");
if (0 !== focusedRowIndex) {
const $firstRow = (0, _renderer.default)(this.getView("rowsView").getRowElement(0));
$firstRow.removeClass("dx-cell-focus-disabled").removeAttr("tabIndex")
}
}
_prepareFocusedRow(options) {
let $row;
const {
changedItem: changedItem
} = options;
if (changedItem && ("data" === changedItem.rowType || "group" === changedItem.rowType)) {
const {
focusedRowIndex: focusedRowIndex
} = options;
const {
$tableElement: $tableElement
} = options;
const tabIndex = this.option("tabindex") || 0;
const rowsView = this.getView("rowsView");
$row = (0, _renderer.default)(rowsView._getRowElements($tableElement).eq(focusedRowIndex));
$row.addClass("dx-row-focused").attr("tabindex", tabIndex)
}
return $row
}
}
exports.FocusController = FocusController;
const keyboardNavigation = Base => class extends Base {
init() {
const rowIndex = this.option("focusedRowIndex");
const columnIndex = this.option("focusedColumnIndex");
this.createAction("onFocusedRowChanging", {
excludeValidators: ["disabled", "readOnly"]
});
this.createAction("onFocusedRowChanged", {
excludeValidators: ["disabled", "readOnly"]
});
this.createAction("onFocusedCellChanging", {
excludeValidators: ["disabled", "readOnly"]
});
this.createAction("onFocusedCellChanged", {
excludeValidators: ["disabled", "readOnly"]
});
super.init();
this.setRowFocusType();
this._focusedCellPosition = {};
if ((0, _type.isDefined)(rowIndex) && rowIndex >= 0) {
this._focusedCellPosition.rowIndex = rowIndex
}
if ((0, _type.isDefined)(columnIndex) && columnIndex >= 0) {
this._focusedCellPosition.columnIndex = columnIndex
}
}
setFocusedRowIndex(rowIndex) {
super.setFocusedRowIndex(rowIndex);
this.option("focusedRowIndex", rowIndex)
}
setFocusedColumnIndex(columnIndex) {
super.setFocusedColumnIndex(columnIndex);
this.option("focusedColumnIndex", columnIndex)
}
_escapeKeyHandler(eventArgs, isEditing) {
if (isEditing || !this.option("focusedRowEnabled")) {
return super._escapeKeyHandler(eventArgs, isEditing)
}
if (this.isCellFocusType()) {
this.setRowFocusType();
this._focus(this.getCellElementFromTarget(eventArgs.originalEvent.target), true);
return true
}
return false
}
_updateFocusedCellPosition($cell, direction) {
const position = super._updateFocusedCellPosition($cell, direction);
if (position && position.columnIndex >= 0) {
this._fireFocusedCellChanged($cell)
}
return position
}
};
exports.keyboardNavigation = keyboardNavigation;
const focusEditorFactoryViewControllerExtender = Base => class extends Base {
init() {
this.keyboardNavigationController = this.getController("keyboardNavigation");
super.init()
}
renderFocusOverlay($element, isHideBorder) {
var _this$keyboardNavigat;
const focusedRowEnabled = this.option("focusedRowEnabled");
if (!focusedRowEnabled || !(null !== (_this$keyboardNavigat = this.keyboardNavigationController) && void 0 !== _this$keyboardNavigat && _this$keyboardNavigat.isRowFocusType()) || this._editingController.isEditing() || this._columnHeadersView.isFilterRowCell($element)) {
super.renderFocusOverlay($element, isHideBorder)
} else if (focusedRowEnabled) {
const isRowElement = "row" === this.keyboardNavigationController._getElementType($element);
if (isRowElement && !$element.hasClass("dx-row-focused")) {
const $cell = this.keyboardNavigationController.getFirstValidCellInRow($element);
this.keyboardNavigationController.focus($cell)
}
}
}
};
exports.focusEditorFactoryViewControllerExtender = focusEditorFactoryViewControllerExtender;
const columns = Base => class extends Base {
init(isApplyingUserState) {
this.focusController = this.getController("focus");
this.dataSourceController = this.getController("dataSource");
super.init(isApplyingUserState)
}
getSortDataSourceParameters(_, sortByKey) {
var _this$dataSourceContr;
let result = super.getSortDataSourceParameters.apply(this, arguments);
let key = null === (_this$dataSourceContr = this.dataSourceController.store()) || void 0 === _this$dataSourceContr ? void 0 : _this$dataSourceContr.key();
const remoteOperations = this.dataSourceController.remoteOperations();
const isLocalOperations = Object.keys(remoteOperations).every(operationName => !remoteOperations[operationName]);
if (key && (this.option("focusedRowEnabled") && false !== this.focusController.isAutoNavigateToFocusedRow() || sortByKey)) {
key = Array.isArray(key) ? key : [key];
const notSortedKeys = key.filter(key => !this.columnOption(key, "sortOrder"));
if (notSortedKeys.length) {
result = result || [];
const sortParameters = result;
if (isLocalOperations) {
result.push({
selector: this.dataSourceController.getDataIndexGetter(),
desc: false
})
} else {
notSortedKeys.forEach(notSortedKey => sortParameters.push({
selector: notSortedKey,
desc: false
}))
}
}
}
return result
}
};
exports.columns = columns;
const focusDataControllerExtender = Base => class extends Base {
callbackNames() {
return [...super.callbackNames(), "afterChanged"]
}
_applyChange(change) {
if (change && "updateFocusedRow" === change.changeType) {
return
}
return super._applyChange.apply(this, arguments)
}
_fireChanged(e) {
super._fireChanged(e);
this.lastChange = e;
this.afterChanged.fire(e)
}
getLastChange() {
return this.lastChange
}
_updatePageIndexes() {
const prevRenderingPageIndex = this._lastRenderingPageIndex || 0;
const renderingPageIndex = this._rowsScrollController ? this._rowsScrollController.pageIndex() : 0;
this._lastRenderingPageIndex = renderingPageIndex;
this._isPagingByRendering = renderingPageIndex !== prevRenderingPageIndex
}
isPagingByRendering() {
return this._isPagingByRendering
}
getPageIndexByKey(key) {
const that = this;
const d = new _deferred.Deferred;
that.getGlobalRowIndexByKey(key).done(globalIndex => {
d.resolve(globalIndex >= 0 ? Math.floor(globalIndex / that.pageSize()) : -1)
}).fail(d.reject);
return d.promise()
}
getGlobalRowIndexByKey(key) {
if (this.dataSourceController.getAdapter().group()) {
return this._calculateGlobalRowIndexByGroupedData(key)
}
return this._calculateGlobalRowIndexByFlatData(key)
}
_calculateGlobalRowIndexByFlatData(key, groupFilter, useGroup) {
const deferred = new _deferred.Deferred;
const dataSourceAdapter = this.dataSourceController.getAdapter();
if (Array.isArray(key) || (0, _m_editing_utils.isNewRowTempKey)(key)) {
return deferred.resolve(-1).promise()
}
let filter = this._generateFilterByKey(key);
dataSourceAdapter.customLoader.load({
filter: this._concatWithCombinedFilter(filter),
skip: 0,
take: 1
}).done(_ref => {
let {
data: data
} = _ref;
if (this.dataSourceController.getAdapter() !== dataSourceAdapter) {
deferred.resolve(-1);
return
}
if (data.length > 0) {
filter = this._generateOperationFilterByKey(key, data[0], useGroup);
dataSourceAdapter.customLoader.load({
filter: this._concatWithCombinedFilter(filter, groupFilter),
skip: 0,
take: 1,
requireTotalCount: true
}).done(_ref2 => {
let {
extra: extra
} = _ref2;
if (this.dataSourceController.getAdapter() !== dataSourceAdapter) {
deferred.resolve(-1);
return
}
deferred.resolve(extra.totalCount)
})
} else {
deferred.resolve(-1)
}
});
return deferred.promise()
}
_concatWithCombinedFilter(filter, groupFilter) {
const combinedFilter = this.getCombinedFilter();
return (0, _utils.combineFilters)([filter, combinedFilter, groupFilter])
}
_generateBooleanFilter(selector, value, sortInfo) {
const {
desc: desc
} = sortInfo;
switch (true) {
case false === value && desc:
return [selector, "=", true];
case false === value && !desc:
return [selector, "=", null];
case true === value && !desc:
case !(0, _type.isBoolean)(value) && desc:
return [selector, "<>", value];
default:
return
}
}
_generateOperationFilterByKey(key, rowData, useGroup) {
const dateSerializationFormat = this.option("dateSerializationFormat");
const remoteOperations = this.dataSourceController.remoteOperations();
const isRemoteFiltering = Boolean(remoteOperations.filtering);
const isRemoteSorting = remoteOperations.sorting;
let filter = this._generateFilterByKey(key, "<");
let sort = this._columnsController.getSortDataSourceParameters(!isRemoteFiltering, true);
if (useGroup) {
const group = this._columnsController.getGroupDataSourceParameters(!isRemoteFiltering);
if (group) {
sort = sort ? group.concat(sort) : group
}
}
if (sort) {
sort.slice().reverse().forEach(sortInfo => {
const {
selector: selector,
desc: desc,
compare: compare
} = sortInfo;
const {
getter: getter,
rawValue: rawValue,
safeValue: safeValue
} = _focus_utils.UiGridCoreFocusUtils.getSortFilterValue(sortInfo, rowData, {
isRemoteFiltering: isRemoteFiltering,
dateSerializationFormat: dateSerializationFormat,
getSelector: selector => this._columnsController.columnOption(selector, "selector")
});
filter = [
[selector, "=", safeValue], "and", filter
];
if (null === rawValue || (0, _type.isBoolean)(rawValue)) {
const booleanFilter = this._generateBooleanFilter(selector, safeValue, desc);
if (booleanFilter) {
filter = [booleanFilter, "or", filter]
}
} else {
const filterOperation = desc ? ">" : "<";
let sortFilter;
if (compare && !isRemoteSorting) {
sortFilter = data => {
if ("<" === filterOperation) {
return compare(rawValue, getter(data)) >= 1
}
return compare(rawValue, getter(data)) <= -1
}
} else {
sortFilter = [selector, filterOperation, safeValue];
if (!desc) {
sortFilter = [sortFilter, "or", [selector, "=", null]]
}
}
filter = [sortFilter, "or", filter]
}
})
}
return filter
}
_generateFilterByKey(key, operation) {
const dataSourceKey = this.dataSourceController.getAdapter().key();
let filter = [];
if (!operation) {
operation = "="
}
if (Array.isArray(dataSourceKey)) {
for (let i = 0; i < dataSourceKey.length; ++i) {
const keyPart = key[dataSourceKey[i]];
if (keyPart) {
if (filter.length > 0) {
filter.push("and")
}
filter.push([dataSourceKey[i], operation, keyPart])
}
}
} else {
filter = [dataSourceKey, operation, key]
}
return filter
}
_getLastItemIndex() {
return this.items(true).length - 1
}
};
exports.focusDataControllerExtender = focusDataControllerExtender;
const editing = Base => class extends Base {
_deleteRowCore(rowIndex) {
const deferred = super._deleteRowCore.apply(this, arguments);
const rowKey = this._dataController.getKeyByRowIndex(rowIndex);
deferred.done(() => {
const rowIndex = this._dataController.getRowIndexByKey(rowKey);
const visibleRows = this._dataController.getVisibleRows();
if (-1 === rowIndex && !visibleRows.length) {
this._focusController._resetFocusedRow()
}
})
}
};
exports.editing = editing;
const rowsView = Base => class extends Base {
_createRow(row) {
const $row = super._createRow.apply(this, arguments);
if (this.option("focusedRowEnabled") && row) {
if (this._focusController.isRowFocused(row.key)) {
$row.addClass("dx-row-focused")
}
}
return $row
}
_checkRowKeys(options) {
super._checkRowKeys.apply(this, arguments);
if (this.option("focusedRowEnabled") && this.option("dataSource")) {
const store = this.dataSourceController.store();
if (store && !store.key()) {
this._dataController.fireError("E1042", "Row focusing")
}
}
}
_update(change) {
if ("updateFocusedRow" === change.changeType) {
if (this.option("focusedRowEnabled")) {
this._focusController.updateFocusedRow(change)
}
} else {
super._update(change)
}
}
updateFocusElementTabIndex($cellElements, preventScroll) {
if (this.option("focusedRowEnabled")) {
this._setFocusedRowElementTabIndex(preventScroll)
} else {
super.updateFocusElementTabIndex($cellElements)
}
}
_setFocusedRowElementTabIndex(preventScroll) {
const focusedRowKey = this.option("focusedRowKey");
const tabIndex = this.option("tabIndex") ?? 0;
const columnsController = this._columnsController;
let rowIndex = this._dataController.getRowIndexByKey(focusedRowKey);
let columnIndex = this.option("focusedColumnIndex");
const $row = this._findRowElementForTabIndex();
const operationTypes = this.dataSourceController.operationTypes();
const isPaging = !operationTypes || operationTypes.paging;
if (!(0, _type.isDefined)(this._scrollToFocusOnResize)) {
this._scrollToFocusOnResize = () => {
this.scrollToElementVertically(this._findRowElementForTabIndex());
this.resizeCompleted.remove(this._scrollToFocusOnResize)
}
}
$row.attr("tabIndex", tabIndex);
const rowIndexFromOption = this.option("focusedRowIndex") - this._dataController.getRowIndexOffset(true);
if (!isPaging && rowIndex < 0 && rowIndexFromOption >= 0) {
this._focusController.updateFocusedRow({
focusedRowKey: focusedRowKey,
preventScroll: preventScroll
})
}
if (rowIndex >= 0 && !preventScroll) {
if (columnIndex < 0) {
columnIndex = 0
}
rowIndex += this._dataController.getRowIndexOffset();
columnIndex += columnsController.getColumnIndexOffset();
this._keyboardNavigationController.setFocusedCellPosition(rowIndex, columnIndex);
if (this._focusController.isAutoNavigateToFocusedRow()) {
if (!isPaging && !this._dataController.isPagingByRendering()) {
this.resizeCompleted.remove(this._scrollToFocusOnResize);
this.resizeCompleted.add(this._scrollToFocusOnResize)
}
}
}
}
_findRowElementForTabIndex() {
const focusedRowKey = this.option("focusedRowKey");
const rowIndex = this._dataController.getRowIndexByKey(focusedRowKey);
return (0, _renderer.default)(this.getRowElement(rowIndex >= 0 ? rowIndex : 0))
}
scrollToRowElement(key) {
const rowIndex = this._dataController.getRowIndexByKey(key);
const $row = (0, _renderer.default)(this.getRow(rowIndex));
return this.scrollToElementVertically($row)
}
scrollToElementVertically($row) {
const scrollable = this.getScrollable();
if (scrollable && $row.length) {
const position = scrollable.getScrollElementPosition($row, "vertical");
return this.scrollTopPosition(position)
}
return (new _deferred.Deferred).resolve()
}
scrollTopPosition(scrollTop) {
const d = new _deferred.Deferred;
const scrollable = this.getScrollable();
if (scrollable) {
const currentScrollTop = scrollable.scrollTop();
const scrollHandler = () => {
scrollable.off("scroll", scrollHandler);
d.resolve()
};
if (scrollTop !== currentScrollTop) {
scrollable.on("scroll", scrollHandler);
this._dataController.resetFilterApplying();
scrollable.scrollTo({
top: scrollTop
});
return d.promise()
}
}
return d.resolve()
}
};
exports.rowsView = rowsView;