Skip to content

Commit

Permalink
Merge pull request #31 from pat310/add-toggle-function
Browse files Browse the repository at this point in the history
add toggle function
  • Loading branch information
pat310 committed Mar 11, 2017
2 parents 6f56fe3 + 1b2f075 commit 13ee601
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export default class Pivot {
return this;
}

toggle(rowNum) {
if (rowNum in this.collapsedRows) {
return this.expand(rowNum);
}
return this.collapse(rowNum);
}

getData(rowNum) {
if (!this.data.table[rowNum]) return null;
if (this.collapsedRows[this.data.table[rowNum].row]) {
Expand Down
16 changes: 16 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,22 @@ describe('pivot', () => {
expect(pivot.getData(1)).to.deep.equal(uncollapsedData);
});

it('should return table to normal state when toggled twice', () => {
const pivot = new Pivot(
dataArray,
rowsToPivot,
colsToPivot,
aggregationCategory,
aggregationType,
);

const startState = pivot.data.table;

pivot.toggle(1).toggle(1);

expect(startState).to.deep.equal(pivot.data.table);
});

it('should expand correct rows', () => {
const pivot = new Pivot(
dataArray,
Expand Down

0 comments on commit 13ee601

Please sign in to comment.