Skip to content

Commit b21e547

Browse files
fix: appendRows bug (#181)
Co-authored-by: ArunMuthuram <65416680+ArunMuthuram@users.noreply.github.com>
1 parent 7ee8ca9 commit b21e547

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ <h1>Frappe DataTable</h1>
2121
<button onclick="datatable.render()">Render Table</button>
2222
<button onclick="datatable.refresh()">Refresh Data</button>
2323
<button onclick="switchToTreeView()" data-action="treeview">TreeView</button>
24+
<button onclick="appendRows()">Append Rows</button>
2425
<label>
2526
<input type="checkbox" id="input-large-data" />
2627
<span>Large Data</span>
@@ -278,6 +279,15 @@ <h1>Frappe DataTable</h1>
278279
console.log(e)
279280
}
280281
};
282+
283+
function appendRows() {
284+
datatable.appendRows(
285+
[
286+
["Garrett", "Accountant", "Tokyo", 8422, "2011/07/25", 170],
287+
["Winters", "Accountant", "Tokyo", 8422, "2011/07/25", 123]
288+
]
289+
)
290+
}
281291
</script>
282292
</body>
283293

src/datamanager.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export default class DataManager {
2929
this.rows = [];
3030

3131
this.prepareColumns();
32-
this.prepareRows();
32+
this.validateData(this.data);
33+
this.rows = this.prepareRows(this.data);
3334
this.prepareTreeRows();
3435
this.prepareRowView();
3536
this.prepareNumericColumns();
@@ -141,10 +142,8 @@ export default class DataManager {
141142
});
142143
}
143144

144-
prepareRows() {
145-
this.validateData(this.data);
146-
147-
this.rows = this.data.map((d, i) => {
145+
prepareRows(data) {
146+
return data.map((d, i) => {
148147
const index = this._getNextRowCount();
149148

150149
let row = [];
@@ -243,8 +242,9 @@ export default class DataManager {
243242

244243
appendRows(rows) {
245244
this.validateData(rows);
246-
247-
this.rows.push(...this.prepareRows(rows));
245+
this.rows = this.rows.concat(this.prepareRows(rows));
246+
this.prepareTreeRows();
247+
this.prepareRowView();
248248
}
249249

250250
sortRows(colIndex, sortOrder = 'none') {

0 commit comments

Comments
 (0)