handsontable
Version:
Handsontable is a JavaScript Data Grid available for React, Angular and Vue.
48 lines • 1.53 kB
JavaScript
import "core-js/modules/es.array.push.js";
import * as C from "../../../i18n/constants.mjs";
/**
* @param {HiddenRows} hiddenRowsPlugin The plugin instance.
* @returns {object}
*/
export default function hideRowItem(hiddenRowsPlugin) {
return {
key: 'hidden_rows_hide',
name() {
const selection = this.getSelectedActive();
let pluralForm = 0;
if (Array.isArray(selection)) {
const [fromRow,, toRow] = selection;
if (fromRow - toRow !== 0) {
pluralForm = 1;
}
}
return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_HIDE_ROW, pluralForm);
},
callback() {
const {
from,
to
} = this.getSelectedRangeActive();
const start = Math.max(Math.min(from.row, to.row), 0);
const end = Math.max(from.row, to.row);
const rowsToHide = [];
for (let visualRow = start; visualRow <= end; visualRow += 1) {
rowsToHide.push(visualRow);
}
hiddenRowsPlugin.hideRows(rowsToHide);
const lastHiddenRow = rowsToHide[rowsToHide.length - 1];
const rowToSelect = this.rowIndexMapper.getNearestNotHiddenIndex(lastHiddenRow, 1, true);
if (Number.isInteger(rowToSelect) && rowToSelect >= 0) {
this.selectRows(rowToSelect);
} else {
this.deselectCell();
}
this.view.adjustElementsSize();
this.render();
},
disabled: false,
hidden() {
return !(this.selection.isSelectedByRowHeader() || this.selection.isSelectedByCorner());
}
};
}