Skip to content

Commit

Permalink
fix: appendRows bug (#181)
Browse files Browse the repository at this point in the history
Co-authored-by: ArunMuthuram <[email protected]>
  • Loading branch information
netchampfaris and ArunMuthuram authored Nov 21, 2023
1 parent 7ee8ca9 commit b21e547
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h1>Frappe DataTable</h1>
<button onclick="datatable.render()">Render Table</button>
<button onclick="datatable.refresh()">Refresh Data</button>
<button onclick="switchToTreeView()" data-action="treeview">TreeView</button>
<button onclick="appendRows()">Append Rows</button>
<label>
<input type="checkbox" id="input-large-data" />
<span>Large Data</span>
Expand Down Expand Up @@ -278,6 +279,15 @@ <h1>Frappe DataTable</h1>
console.log(e)
}
};

function appendRows() {
datatable.appendRows(
[
["Garrett", "Accountant", "Tokyo", 8422, "2011/07/25", 170],
["Winters", "Accountant", "Tokyo", 8422, "2011/07/25", 123]
]
)
}
</script>
</body>

Expand Down
14 changes: 7 additions & 7 deletions src/datamanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default class DataManager {
this.rows = [];

this.prepareColumns();
this.prepareRows();
this.validateData(this.data);
this.rows = this.prepareRows(this.data);
this.prepareTreeRows();
this.prepareRowView();
this.prepareNumericColumns();
Expand Down Expand Up @@ -141,10 +142,8 @@ export default class DataManager {
});
}

prepareRows() {
this.validateData(this.data);

this.rows = this.data.map((d, i) => {
prepareRows(data) {
return data.map((d, i) => {
const index = this._getNextRowCount();

let row = [];
Expand Down Expand Up @@ -243,8 +242,9 @@ export default class DataManager {

appendRows(rows) {
this.validateData(rows);

this.rows.push(...this.prepareRows(rows));
this.rows = this.rows.concat(this.prepareRows(rows));
this.prepareTreeRows();
this.prepareRowView();
}

sortRows(colIndex, sortOrder = 'none') {
Expand Down

0 comments on commit b21e547

Please sign in to comment.