mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 08:33:58 +00:00
split columns macro
This commit is contained in:
@@ -277,6 +277,50 @@ return {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: 'Split columns',
|
||||||
|
name: 'splitColumns',
|
||||||
|
group: 'Tools',
|
||||||
|
description: 'Split selected columns',
|
||||||
|
type: 'transformData',
|
||||||
|
code: `
|
||||||
|
const selectedColumnNames = modules.lodash.uniq(selectedCells.map(x => x.column));
|
||||||
|
const selectedRowIndexes = modules.lodash.uniq(selectedCells.map(x => x.row));
|
||||||
|
|
||||||
|
const addedColumnNames = new Set();
|
||||||
|
|
||||||
|
const resultRows = modules.lodash.cloneDeep(rows);
|
||||||
|
resultRows.forEach((row, rowIndex) => {
|
||||||
|
for(const cell of selectedCells) {
|
||||||
|
if (cell.row == rowIndex && modules.lodash.isString(cell.value)) {
|
||||||
|
const splitted = cell.value.split(args.delimiter);
|
||||||
|
splitted.forEach((value, valueIndex) => {
|
||||||
|
const name = cell.column + '_' + (valueIndex + 1).toString();
|
||||||
|
row[name] = value;
|
||||||
|
addedColumnNames.add(name);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const resultCols = [
|
||||||
|
...cols,
|
||||||
|
...addedColumnNames,
|
||||||
|
];
|
||||||
|
return {
|
||||||
|
rows: resultRows,
|
||||||
|
cols: resultCols,
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
label: 'Delimiter',
|
||||||
|
name: 'delimiter',
|
||||||
|
default: ','
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'Calculation',
|
title: 'Calculation',
|
||||||
name: 'calculation',
|
name: 'calculation',
|
||||||
|
|||||||
Reference in New Issue
Block a user