Skip to content

Commit

Permalink
fix issue with onRenderered function being called to early
Browse files Browse the repository at this point in the history
  • Loading branch information
olifolkerd committed Jul 23, 2023
1 parent a8caf1a commit 87980d5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
37 changes: 24 additions & 13 deletions dist/js/tabulator_esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3112,7 +3112,7 @@ class Row extends CoreFeature{
}

//functions to setup on first render
initialize(force){
initialize(force, inFragment){
this.create();

if(!this.initialized || force){
Expand All @@ -3127,7 +3127,7 @@ class Row extends CoreFeature{

this.initialized = true;

this.table.columnManager.renderer.renderRowCells(this);
this.table.columnManager.renderer.renderRowCells(this, inFragment);

if(force){
this.normalizeHeight();
Expand All @@ -3141,9 +3141,15 @@ class Row extends CoreFeature{

this.dispatch("row-layout-after", this);
}else {
this.table.columnManager.renderer.rerenderRowCells(this);
this.table.columnManager.renderer.rerenderRowCells(this, inFragment);
}
}

rendered(){
this.cells.forEach((cell) => {
cell.cellRendered();
});
}

reinitializeHeight(){
this.heightInitialized = false;
Expand Down Expand Up @@ -20583,19 +20589,21 @@ class BasicHorizontal extends Renderer{
constructor(table){
super(table);
}

renderRowCells(row) {
renderRowCells(row, inFragment) {
const rowFrag = document.createDocumentFragment();
row.cells.forEach((cell) => {
rowFrag.appendChild(cell.getElement());
});
row.element.appendChild(rowFrag);

row.cells.forEach((cell) => {
cell.cellRendered();
});

if(!inFragment){
row.cells.forEach((cell) => {
cell.cellRendered();
});
}
}

reinitializeColumnWidths(columns){
columns.forEach(function(column){
column.reinitializeWidth();
Expand Down Expand Up @@ -22288,13 +22296,14 @@ class VirtualDomVertical extends Renderer{
rowFragment = document.createDocumentFragment();

i = 0;

while ((i < rowsToRender) && this.vDomBottom < rowsCount -1) {
index = this.vDomBottom + 1,
row = rows[index];

this.styleRow(row, index);

row.initialize();
row.initialize(false, true);
if(!row.heightInitialized && !this.table.options.rowHeight){
row.clearCellHeight();
}
Expand All @@ -22308,21 +22317,23 @@ class VirtualDomVertical extends Renderer{
if(!renderedRows.length){
break;
}

element.appendChild(rowFragment);

// NOTE: The next 3 loops are separate on purpose
// This is to batch up the dom writes and reads which drastically improves performance

renderedRows.forEach((row) => {
row.rendered();

if(!row.heightInitialized) {
row.calcHeight(true);

}
});

renderedRows.forEach((row) => {
if(!row.heightInitialized) {
row.setCellHeight();

}
});

Expand Down
2 changes: 1 addition & 1 deletion dist/js/tabulator_esm.js.map

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions src/js/core/rendering/renderers/BasicHorizontal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ export default class BasicHorizontal extends Renderer{
constructor(table){
super(table);
}

renderRowCells(row) {
renderRowCells(row, inFragment) {
const rowFrag = document.createDocumentFragment();
row.cells.forEach((cell) => {
rowFrag.appendChild(cell.getElement());
});
row.element.appendChild(rowFrag);

row.cells.forEach((cell) => {
cell.cellRendered();
});

if(!inFragment){
row.cells.forEach((cell) => {
cell.cellRendered();
});
}
}

reinitializeColumnWidths(columns){
columns.forEach(function(column){
column.reinitializeWidth();
Expand Down
9 changes: 6 additions & 3 deletions src/js/core/rendering/renderers/VirtualDomVertical.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,14 @@ export default class VirtualDomVertical extends Renderer{
rowFragment = document.createDocumentFragment();

i = 0;

while ((i < rowsToRender) && this.vDomBottom < rowsCount -1) {
index = this.vDomBottom + 1,
row = rows[index];

this.styleRow(row, index);

row.initialize();
row.initialize(false, true);
if(!row.heightInitialized && !this.table.options.rowHeight){
row.clearCellHeight();
}
Expand All @@ -307,21 +308,23 @@ export default class VirtualDomVertical extends Renderer{
if(!renderedRows.length){
break;
}

element.appendChild(rowFragment);

// NOTE: The next 3 loops are separate on purpose
// This is to batch up the dom writes and reads which drastically improves performance

renderedRows.forEach((row) => {
row.rendered();

if(!row.heightInitialized) {
row.calcHeight(true);

}
});

renderedRows.forEach((row) => {
if(!row.heightInitialized) {
row.setCellHeight();

}
});

Expand Down
12 changes: 9 additions & 3 deletions src/js/core/row/Row.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class Row extends CoreFeature{
}

//functions to setup on first render
initialize(force){
initialize(force, inFragment){
this.create();

if(!this.initialized || force){
Expand All @@ -80,7 +80,7 @@ export default class Row extends CoreFeature{

this.initialized = true;

this.table.columnManager.renderer.renderRowCells(this);
this.table.columnManager.renderer.renderRowCells(this, inFragment);

if(force){
this.normalizeHeight();
Expand All @@ -94,9 +94,15 @@ export default class Row extends CoreFeature{

this.dispatch("row-layout-after", this);
}else{
this.table.columnManager.renderer.rerenderRowCells(this);
this.table.columnManager.renderer.rerenderRowCells(this, inFragment);
}
}

rendered(){
this.cells.forEach((cell) => {
cell.cellRendered();
});
}

reinitializeHeight(){
this.heightInitialized = false;
Expand Down

0 comments on commit 87980d5

Please sign in to comment.