Skip to content

Commit 4ddecb3

Browse files
Anselm JosephAnselm Joseph
authored andcommitted
added insert data
1 parent a51e0bf commit 4ddecb3

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

demo/demo1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
}
8181

8282
moderno.registerLazyLoadTriggerCallback((completion) => {
83-
// alert("callback");
83+
moderno.appendData(newData)
8484
setTimeout(() => {
8585
completion();
8686
}, 1000)

dist/table-moderno.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,36 @@ class TableModerno {
572572
$(`#${this.tableID}.moderno-table-wrapper`).scroll();
573573
}
574574

575+
/**
576+
* Load more data into table and re-set widths for new items
577+
* @param {Object} data New data to load the table with
578+
*/
579+
appendData(data, keepSort = false) {
580+
this.prevTableData = [...this.prevTableData, ...data];
581+
this.tableData = [...this.tableData, ...data];
582+
583+
if (!keepSort) {
584+
this.resetSortList();
585+
}
586+
587+
var colKeys = this.getHeaderColumnDataKeys();
588+
var clipClass = this.config.singleLineRows ? "clip" : "no-clip";
589+
590+
var dataString = "";
591+
for (var i = 0; i < data.length; i++) {
592+
dataString += this.getRowString(i, colKeys, clipClass);
593+
}
594+
let oldHtml = $(`#${this.tableID} .moderno-table-body`).html()
595+
$(`#${this.tableID} .moderno-table-body`).html(oldHtml + dataString);
596+
597+
this.setWidthByColumn(this.config.widthByColumn);
598+
this.registerStickyColumnsLeft(this.config.stickColumnsLeft);
599+
this.registerStickyColumnsRight(this.config.stickColumnsRight);
600+
this.showTooltip();
601+
$(`#${this.tableID}.moderno-table-wrapper`).scroll();
602+
}
603+
604+
575605
/**
576606
* Create a HTML string for new row to be inserted
577607
* @param {Object} row Object containing the information of row data

0 commit comments

Comments
 (0)