Skip to content

Commit 0c97de5

Browse files
authored
Merge pull request #39 from enso-ui/feature/nestedColumnsFormatting
implements number formatting for nested columns
2 parents 93f4831 + f6c015f commit 0c97de5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/renderless/services/NumberFormatter.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class NumberFormatter {
22
constructor(vm, column) {
33
this.vm = vm;
44
this.column = column;
5+
this.segments = column.name.split('.');
56
this.totals = this.hasTotal();
67
}
78

@@ -10,9 +11,11 @@ class NumberFormatter {
1011
}
1112

1213
replace(column) {
13-
this.vm.body.data = this.vm.body.data.map((row, index) => {
14-
row[this.column.name] = column[index];
15-
return row;
14+
const { length } = this.segments;
15+
this.vm.body.data.forEach((row, index) => {
16+
this.segments.forEach((segment, idx) => idx + 1 === length
17+
? (row[segment] = column[index])
18+
: row = row[segment])
1619
});
1720

1821
if (this.totals) {
@@ -32,7 +35,8 @@ class NumberFormatter {
3235
}
3336

3437
numbers() {
35-
const column = this.vm.body.data.map(row => row[this.column.name]);
38+
const column = this.vm.body.data
39+
.map(row => this.segments.reduce((row, segment) => row[segment], row));
3640

3741
if (this.totals) {
3842
column.push(this.vm.body.total[this.column.name]);

0 commit comments

Comments
 (0)