Skip to content

Commit

Permalink
fix: 🐛 Extract getTotalRow into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
netchampfaris committed Dec 7, 2018
1 parent 96c7b72 commit 1e20502
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/body-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export default class BodyRenderer {
renderFooter() {
if (!this.options.showTotalRow) return;

const totalRow = this.getTotalRow();
let html = this.rowmanager.getRowHTML(totalRow, { isTotalRow: 1, rowIndex: 'totalRow' });

this.footer.innerHTML = html;
}

getTotalRow() {
const columns = this.datamanager.getColumns();
const totalRowTemplate = columns.map(col => {
let content = 0;
Expand All @@ -60,7 +67,6 @@ export default class BodyRenderer {
column: col
};
});

const totalRow = this.visibleRows.reduce((acc, prevRow) => {
return acc.map((cell, i) => {
const prevCell = prevRow[i];
Expand All @@ -73,10 +79,7 @@ export default class BodyRenderer {
return Object.assign({}, cell);
});
}, totalRowTemplate);

let html = this.rowmanager.getRowHTML(totalRow, { isTotalRow: 1, rowIndex: 'totalRow' });

this.footer.innerHTML = html;
return totalRow;
}

restoreState() {
Expand Down

0 comments on commit 1e20502

Please sign in to comment.