31 lines
721 B
TypeScript
31 lines
721 B
TypeScript
import {Table, Sum} from './table';
|
|
|
|
var table: Table;
|
|
var rows: Array<Array<string>>;
|
|
|
|
rows = [
|
|
["a","1"],
|
|
["b","2"],
|
|
["a","3"],
|
|
["b","1"],
|
|
["a","2"],
|
|
["b","3"],
|
|
];
|
|
|
|
table = new Table("Root", rows, [1]);
|
|
table.PivotTree([0, 1]);
|
|
table.ItrLeaves( (inTable: Table) =>
|
|
{
|
|
inTable.Columns.forEach( (inColumn: Sum, inIndex: number) =>
|
|
{
|
|
inTable.Rows.forEach( (inRow: Array<string>) =>
|
|
{
|
|
inColumn.Original += parseFloat(inRow[inColumn.ColumnIndex]);
|
|
});
|
|
inTable.ItrParents( (inParent: Table)=>
|
|
{
|
|
inParent.Columns[inIndex].Original += inColumn.Original;
|
|
});
|
|
});
|
|
} );
|
|
table.ItrChildren( inTable => console.log(inTable) ); |