MCPcopy Create free account
hub / github.com/handsontable/handsontable / removeCol

Function removeCol

handsontable/src/core.ts:1049–1118  ·  view source on GitHub ↗
(indexes: number[][])

Source from the content-addressed store, hash-verified

1047 case 'remove_col':
1048
1049 const removeCol = (indexes: number[][]) => {
1050 let offset = 0;
1051
1052 // Normalize the {index, amount} groups into bigger groups.
1053 arrayEach(indexes, ([groupIndex, groupAmount]) => {
1054
1055 const calcIndex = isEmpty(groupIndex) ? instance.countCols() - 1 : Math.max(groupIndex - offset, 0);
1056
1057 let physicalColumnIndex = instance.toPhysicalColumn(calcIndex);
1058
1059 // If the 'index' is an integer decrease it by 'offset' otherwise pass it through to make the value
1060 // compatible with datamap.removeCol method.
1061 if (Number.isInteger(groupIndex)) {
1062
1063 groupIndex = Math.max(groupIndex - offset, 0);
1064 }
1065
1066 // TODO: for datamap.removeCol index should be passed as it is (with undefined and null values). If not, the logic
1067 // inside the datamap.removeCol breaks the removing functionality.
1068 const wasRemoved = datamap.removeCol(groupIndex, groupAmount, source);
1069
1070 if (!wasRemoved) {
1071 return;
1072 }
1073
1074 if (selection.isSelected()) {
1075 const { col } = instance.getSelectedRangeActive()!.highlight;
1076
1077 if (col! >= groupIndex && col! <= groupIndex + groupAmount - 1) {
1078 editorManager.closeEditor(true);
1079 }
1080 }
1081
1082 const totalColumns = instance.countCols();
1083
1084 if (totalColumns === 0) {
1085 selection.deselect();
1086
1087 } else if (source === 'ContextMenu.removeColumn') {
1088 const selectionRange = selection.getSelectedRange()!;
1089 const lastSelection = selectionRange.pop()!;
1090
1091 selectionRange
1092 .clear()
1093 .set(lastSelection.from)
1094 .current()!
1095 .setTo(lastSelection.to);
1096
1097 selection.refresh();
1098
1099 } else {
1100 selection.shiftColumns(groupIndex, -groupAmount);
1101 }
1102
1103 const fixedColumnsStart = tableMeta.fixedColumnsStart;
1104
1105 if (fixedColumnsStart >= calcIndex + 1) {
1106 tableMeta.fixedColumnsStart -= Math.min(groupAmount, fixedColumnsStart - calcIndex);

Callers 1

alterFunction · 0.85

Calls 15

arrayEachFunction · 0.90
isEmptyFunction · 0.90
toPhysicalColumnMethod · 0.80
removeColMethod · 0.80
isSelectedMethod · 0.80
closeEditorMethod · 0.80
setToMethod · 0.80
currentMethod · 0.80
shiftColumnsMethod · 0.80
countColsMethod · 0.65
getSelectedRangeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…